471,602 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,602 software developers and data experts.

.NET Socket-ReConnection Error-Connecting To UnWorking Server Sock

First of all I wish you a good day.

My help request is about .NET asynchrounus socket communication. I have
developed Server-Client Windows Forms .NET applications in VC++ .NET v2003. I
have several problems re-establishin connection between peers. Below are my
problem cases after closing of the first successfull communication;

#1) I re-start the Server to accept connection requests. While it is
waiting, I run the Client. It is connecting to server socket and waits for
the data communication. But at this time, my server program is still waiting
at "BeginAccept". Nothing changes at its status.
#2) I re-start the Server to accept connection requests. While it is
waiting, I run the Client. It gives 10061 WSAECONNREFUSED (Connection refused
by host)
#3) After first successful communication closing, I start the Client to
connect to server 2-4 seconds later. It connects to a server socket however
my server socket program is not started to accept connection requests at this
time. Then, Client program waits for data communication.

I checked the working TCP sockets with "netstat -n -o 2" command. After the
closing of the first successfull communication, first server socket's status
either TIME_WAIT and several seconds later CLOSE_WAIT, or when it TIME_WAIT,
new connection is being set with same server IP:PORT with clietn socket
(problems at #1 and #3)

I shutdown and close my sockets using the same commands. Below is the
function, that is same for both;

static Socket *m_ServerSocket = NULL; // *m_ClientSocket = NULL;

System::Void mf_Shutdown_And_Close()
try {
if (m_ServerSocket != NULL)
if ( m_ServerSocket->Connected )

m_ServerSocket = NULL;

mf_ChangeButtonStatusTo( ConnStatus::CONNECT );
catch(Exception *exp) {
// Programda hata durumunu göster

Below are the options of my sockets
Server Socket:
SetSocketOption(..., SocketOptionName::ReuseAddress, true);
SetSocketOption(..., SocketOptionName::KeepAlive, true);
SetSocketOption(..., SocketOptionName::DontLinger, true);
Client Socket:
SetSocketOption(..., SocketOptionName::DontLinger, true );

Previously, I developed similar Server-Client programs using native C++
and blocking codes. I didnot faced with this kind of problems. Why Server
socket is not closing totally after succesfull Shutdown() and Close()

I put Thread::Sleep(..) to let the program give time to system to release
resources. Even Using GC::Collect() did not useful.

Thank you very much in advance for your helps.

PS: You may check my programs

I use
Windows XP Pro
Visual C++ .NET Standard v2003
..NET Framework 3.0
Windows Forms .NET application

İyi Çalışmalar / Wish You Good Work
Alper AKÇAYÖZ (Bil Muh)
Feb 21 '07 #1
0 2428

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chuck E. Cheese | last post: by
10 posts views Thread by groups.20.thebriguy | last post: by
8 posts views Thread by Mark Fink | last post: by
3 posts views Thread by Giampaolo Rodola' | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.