异步通讯
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);
}
});