请问在Socket类中如何实现超时重发?
Socket基于TCP,处于阻塞模式。函数结构如下
private String SendAndReceive(Byte[] temp, Int32 location, int length)
{
bool Sending = true;
bool firstSend = true;
while (Sending)
{
try
{
if(!firstSend)
{
Sending = false;
}
skSocket.Send(temp, (length + 4), SocketFlags.None);
num = skSocket.Receive(byt);
str = byt.ToString();
return str;
}
catch (Exception error)
{
if (firstSend)
{
firstSend = false;
}
else
{
throw new Exception;
}
}
}
}
在这个结构下,一旦skSocket.Receive发生超时,再次调用时就直接处于超时状态,而不是等待skSocket.ReceiveTimeout时间后再超时。请问如何清除skSocket.Receive的超时标志?
------解决方案--------------------我看见别人是把skSocket的接收缓冲区直接每次清空
------解决方案--------------------牧野老兄的博客上有
http://blog.csdn.net/wzd24/archive/2007/04/13/1564112.aspx
------解决方案--------------------www.lslnet.com/linux/dosc1/34/linux-260387.htm