我正在使用 aStreamSocketListener
在 Windows Phone 8(充当服务器)上接收由 HTTP POST 客户端发送的数据。我可以接收数据,但是当读取所有数据时,该DataReader.LoadAsync()
方法会挂起,直到我手动取消来自客户端的连接:
_streamSocket = new StreamSocketListener();
_streamSocket.ConnectionReceived += _streamSocket_ConnectionReceived;
await _streamSocket.BindServiceNameAsync("30000");
private async void _streamSocket_ConnectionReceived(StreamSocketListener sender,
StreamSocketListenerConnectionReceivedEventArgs args)
{
using (IInputStream inStream = args.Socket.InputStream)
{
DataReader reader = new DataReader(inStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
do
{
numReadBytes = await reader.LoadAsync(1 << 20); // "Hangs" when all data is read until the client cancels the connection, e.g. numReadBytes == 0
System.Diagnostics.Debug.WriteLine("Read: " + numReadBytes);
// Process data
if (numReadBytes > 0)
{
byte[] tmpBuf = new byte[numReadBytes];
reader.ReadBytes(tmpBuf);
}
} while (numReadBytes > 0);
}
System.Diagnostics.Debug.WriteLine("Finished reading");
}
这个示例代码有什么问题?