异步通讯

Task.Factory.StartNew(() =>
{
try
{
#region contents
byte[] byteData = new byte[1]; //0000 0101
byteData[0] = 5;
byte[] recBytes = new byte[1];
string recStr = "";

//send 5 握手前先发送5
_clientSocket.Send(byteData);

//receive 6 收到6后再发送数据
_clientSocket.Receive(recBytes);
recStr = bytesToString(recBytes);

//send message
if (recStr == "ACK") //ACK = 6
{
_clientSocket.Send(stringToBytes(sendStr));
}
else
{
_sendList.Add(sendStr);
}
#endregion
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
});

posted @ 2019-11-13 16:50  CocoWang  阅读(111)  评论(0编辑  收藏  举报