流套接字读取器接收0字节和应用程序崩溃(windows phone 8)
本文关键字:崩溃 应用程序 windows phone 字节 读取 套接字 | 更新日期: 2023-09-27 18:08:02
如何处理来自阅读器的空数据(0字节)?我的应用程序保持强制关闭时,它接收到null数据。下面是我的代码:
int i = 0;
private async void ReceiveData()
{
if (socket != null)
{
uint s = await dataReader.LoadAsync(1);
string data = dataReader.ReadString(s);
Debug.WriteLine(s);
if (data=="X")
{
i++;
}
if (data == null)
{
// what should I put here?
}
txtMessage.Text = i.ToString();
}
}
当我的应用程序接收到null数据并突然被迫关闭时,我遇到了麻烦。当我的应用程序接收到一个空数据并等待下一个传入数据时,有什么代码吗?
在这种情况下,我希望dataReader继续读取传入的数据,即使数据为空(没有接收到数据),并等待,直到它获得下一个传入的数据。你会怎么做呢?
谢谢
要重复操作,请使用while
循环。
但是,如果您从套接字流中读取零字节,则意味着套接字已关闭,您应该停止读取