windows phone8.1 socket出现问题
private async void ReceiveFromServer()
{
StreamSocket clientSock = new StreamSocket();
byte a;
try
{
HostName sh = new HostName("10.210.106.43");
await clientSock.ConnectAsync(sh, "12347");
}
catch (Exception ex)
{
clientSock.Dispose();
clientSock = null;
num.Text = "wrong connect server";
return;
}
tbFileName.Text = "ok";// 这只是一个textblock
try
{
DataReader reader = new DataReader(clientSock.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
var l = await reader.LoadAsync(sizeof(byte));
num.Text = l.ToString();
a = reader.ReadByte();
num.Text = a.ToString();// num也是一个textblock
}
catch (Exception ex)
{
num.Text = ex.ToString(); // num也是一个textblock
return;
}
}
手机上的结果是:tbFileName.Text = "ok";// 这只是一个textblock: 这个ok能输出,服务器那边我在linux下写的一个server端,那边显示已经连上,并每隔一秒发送一个字节,那边显示发送ok。
后面的 num.Text = ex.ToString(); // num也是一个textblock :
System.OutOfMemoryException: Insuffcient memory to continue the execution of the program.
at Windows.Storage.Streams.DataReader.LoadAsync(UInt32 count)
at App1.MainPage.<connect>d_1a.MoveNext()
这个app只是自己试验的,并没有其他功能,就只有这个,绝对不可能发生内存不够的情况,大神来看一看。thank you。