Hi Gurus,
I have a C# project on VS2008, Framework 3.5.
I'm using a TCP socket like that:
Socket mClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
mClientSocket.NoDelay = true;
mClientSocket.Blocking = true;
mClientSocket.DontFragment = false;
mClientSocket.LingerState.Enabled = false;
mClientSocket.LingerState.LingerTime = 0;
mClientSocket.UseOnlyOverlappedIO = true;
// Get the remote IP address.
System.Net.IPAddress[] IPs = System.Net.Dns.GetHostAddresses(ExchangeIPAddress); // ExchangeIPAddress is a string with the IP address
IPAddress ip = IPs[0];
int iPortNo = System.Convert.ToInt32(ExchangePort);// ExchangePort is string with the port
// Create the end point.
IPEndPoint ipEnd = new IPEndPoint(ip, iPortNo);
// Connect to the remote host.
mClientSocket.Connect(ipEnd);
I have some cases that the socket is hanging on CLOSE_WAIT (shown on the Process Explorer), and stay like that forever, causing the data flow to cease.
There is no error return value anywhere, and no exception is thrown.
Therefore; I have no idea to what can cause this. Only closing the client application and starting it again, solve the problem. I this client restart is not acceptable solution.
Can anyone aid me to find what might cause this CLOSE_WAIT to hang like that?
--
Thanks
Sharon
Loading
SharonPosted Sep 28, 2010, 3:06 AM
I'm using this socket to send data to the server by:
Int32 sentByteCount = 0;
do
{
sentByteCount += mClientSocket.Send(byData, sentByteCount, byData.Length - sentByteCount, SocketFlags.None);
}
while( sentByteCount < byData.Length );
and in any error/exception I'm doing:
mClientSocket.Disconnect(false);
mClientSocket.Shutdown(SocketShutdown.Both);
mClientSocket.Close();
mClientSocket = null;
And then creating the socket again and reconnecting as I posted before.
I can't be sure that no other error function fails, but in any case of an error, I'm writing it to a log, and the log is empty. So I believe there is no other error.
I'm also not sure the Connect was successful because I can't tell what can cause this hanging CLOSE_WAIT.
I'm simply in the blur…
--------
Thanks
Sharon
Sam HobbsPosted Sep 27, 2010, 6:39 PM