socket同步接收数据时,经常报异常,很不稳定,求解!!!
异常:已引发: "由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。"
(System.Net.Sockets.SocketException) 引发了一个
System.Net.Sockets.SocketException:
"由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。" 时间: 2015/6/25 21:29:42 线程:
<无名称>[10136]
while (validate)
{
Thread.Sleep(500);
int readsize;
bool success;
IPEndPoint clientipe = (IPEndPoint)listensocket2.RemoteEndPoint;
byte commandByte = Hex.HexStringToByteArray(command_8);
Logger.Info("D:\\Log\\" + hostcode + ".txt", "循环5.1. 发送命令\n");
listensocket2.Send(commandByte, 0, commandByte.Length, SocketFlags.None);
hostList = AddClient(hostcode, listensocket2, clientipe.Address.ToString(), DateTime.Now, DateTime.Now); //加入客户端对象列表
listensocket2.ReceiveTimeout = 5000;
int countSocketException = 0;
//try
//{
Logger.Info("D:\\Log\\" + hostcode + ".txt", "循环5.2. 接收数据前" + buffer_receive + "|||listensocket2状态:" + listensocket2.Connected + "|||" + listensocket2. + "\n");
readsize = listensocket2.Receive(buffer_receive);
Logger.Info("D:\\Log\\" + hostcode + ".txt", "循环5.3. 接收数据后\n");