I have chat application developed in vb.net . It is used to chat between PC's which are connected in LAN network inside a office. It uses TCP/IP port 25025 to connect to another. The app works fine . But in some cases receiver won't get the chat message.
So I just run the netstat -an
command in that pc and find so many tcp ports and its state. Below is a part of it (error case). I have shown only lines which has 25025 in it.
Proto Local Address Foreign Address State
TCP 0.0.0.0:25025 0.0.0.0:0 LISTENING
TCP 192.168.1.79:25025 192.168.1.60:1320 TIME_WAIT
TCP 192.168.1.79:25025 192.168.1.60:1321 TIME_WAIT
TCP 192.168.1.79:58508 192.168.1.60:25025 TIME_WAIT
TCP 192.168.1.79:58509 192.168.1.60:25025 TIME_WAIT
TCP 192.168.1.79:58510 192.168.1.60:25025 TIME_WAIT
TCP 192.168.1.79:58511 192.168.1.60:25025 ESTABLISHED
Then i checked the same command where i didn't get any error with my app (proper working of my app). The output was,
TCP 192.168.1.60:25025 192.168.1.79:58511 ESTABLISHED
So how can i troubleshoot it? What does this so many port with 25025 indicate. In the error case i have lot of 25025 port as above shown. So please help me in understanding this and solve the problem.
Check to see whether the bind() call is succeeding or not. My guess is that when your application binds to the listening port it fails with the error "address already in use". The TIME_WAIT lines in the netstat output suggest this is so. But I'm guessing that your application isn't checking the return value from bind() and is blindly continuing assuming that the call succeeded. This would explain why it never receives anything.
You get "address already in use" if the socket has not completed its shutdown from an previous invocation of the application. Typically it takes about 4 minutes for the socket to be ready to be reused after it has been closed by the application, and in the meantime the state is TIME_WAIT.
You could use the SO_REUSEADDR socket option to avoid this TIME_WAIT period.