gpt4 book ai didi

c# - Windows 8 Consumer Preview + Visual Studio 11 Developer Preview 中的 Socket BUG

转载 作者:行者123 更新时间:2023-11-30 18:00:47 28 4
gpt4 key购买 nike

我正在 Visual Studio 11 Developer Preview 中编写应用程序,在应用程序与 reader 一起运行一段时间后出现此错误。InputStreamOptions = InputStreamOptions.Partial;选项集:

An unhandled exception of type 'System.Exception' occurred in mscorlib.dll

Additional information: The operation attempted to access data outside the valid range (Exception from HRESULT: 0x8000000B)

当该选项未设置时,套接字可以正常读取流。

引用代码如下:

   private StreamSocket tcpClient;
public string Server = "10.1.10.64";
public int Port = 6000;
VideoController vCtrl = new VideoController();
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
tcpClient = new StreamSocket();
Connect();
this.InitializeComponent();
this.Suspending += OnSuspending;
}

public async void Connect()
{
await tcpClient.ConnectAsync(
new Windows.Networking.HostName(Server),
Port.ToString(),
SocketProtectionLevel.PlainSocket);

DataReader reader = new DataReader(tcpClient.InputStream);
Byte[] byteArray = new Byte[1000];
//reader.InputStreamOptions = InputStreamOptions.Partial;
while (true)
{


await reader.LoadAsync(1000);
reader.ReadBytes(byteArray);

// unsafe
//{
// fixed(Byte *fixedByteBuffer = &byteArray[0])
// {
vCtrl.Consume(byteArray);
vCtrl.Decode();
// }
//}
}


}

最佳答案

InputStreamOptions.Partial 表示 LoadAsync 可能会在少于请求的可用字节数时完成。因此,您不一定能读取完整的请求缓冲区大小。

试试这个:

public async void Connect()
{
await tcpClient.ConnectAsync(
new Windows.Networking.HostName(Server),
Port.ToString(),
SocketProtectionLevel.PlainSocket);

DataReader reader = new DataReader(tcpClient.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
while (true)
{
var bytesAvailable = await reader.LoadAsync(1000);
var byteArray = new byte[bytesAvailable];
reader.ReadBytes(byteArray);

// unsafe
//{
// fixed(Byte *fixedByteBuffer = &byteArray[0])
// {
vCtrl.Consume(byteArray);
vCtrl.Decode();
// }
//}
}
}

顺便说一句,报告 Microsoft 错误的正确位置是 Microsoft Connect .

关于c# - Windows 8 Consumer Preview + Visual Studio 11 Developer Preview 中的 Socket BUG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9709961/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com