我尝试在我的 Windows 8 应用程序中从 websocket 接收字节,但如果我 readStream.CopyTo(memoryStream);
用来获取字节但应用程序工作异常。有谁知道我如何从接收字节中获取字节数组?我向服务器发送 7 个字节,然后得到 1752 个字节,但现在我不知道如何获取这些字节,我可能只计算字节数。我使用标准的 Windows 8 示例 Connecting with WebSockets 示例(Windows 8)。
private async void ReceiveData(object state)
{
int bytesReceived = 0;
try
{
Stream readStream = (Stream)state;
int read = await readStream.ReadAsync(readBuffer, 0, readBuffer.Length);
bytesReceived += read;
MarshalText(DataReceivedField, bytesReceived.ToString(), false);
using (var memoryStream = new MemoryStream())
{
readStream.CopyTo(memoryStream);
}
}
catch (...)
{
....
}
}