TCP Socket.Connect is generating false positives
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2009-04-06T22:56:36Z
Indexed on
2010/05/20
7:50 UTC
Read the original article
Hit count: 234
I'm experiencing really weird behavior with the Socket.Connect method in C#. I am attempting a TCP Socket.Connect to a valid IP but closed port and the method is continuing as if I have successfully connected. When I packet sniffed what was going on I saw that the app was receiving RST packets from the remote machine. Yet from the tracing that is in place it is clear that the connect method is not throwing an exception. Any ideas what might be causing this?
The code that is running is basically this
IPEndPoint iep =
new IPEndPoint(System.Net.IPAddress.Parse(m_ipAddress), m_port);
Socket tcpSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
tcpSocket.Connect(iep);
To add to the mystery... when running this code in a stand alone console application, the result is as expected – the connect method throws an exception. However, when running it in the Windows Service deployment we have the connect method does not throw an exception.
Edit in response to Mystere Man's answer How would the exception be swallowed? I have a Trace.WriteLine right above the .Connect method and a Trace.WriteLine right under it (not shown in the code sample for readability). I know that both traces are running. I also have a try catch around the whole thing which also does a Trace.Writeline and I don't see that in the log files anywhere. I have also enabled the internal socket tracing as you suggested. I don't see any exceptions. I see what appears to be successful connections.
I am trying to identify differences between the windows service app and the diagnostic console app I made. I am running out of ideas though
End edit
Thanks
© Stack Overflow or respective owner