473,503 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hello,
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->Shutdown(SocketShutdown::Both);
Thread::Sleep(250);
}

m_ServerSocket->Close();
m_ServerSocket = NULL;
Thread::Sleep(500);

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);
and
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()
commands?

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
www.AlperAkcayoz.com/PRG/AsynchSoket-CppNET.zip

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)
www.AlperAkcayoz.com
Feb 21 '07 #1
0 2574

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16578
by: Chuck E. Cheese | last post by:
I need a php page to connect to a python created socket and sent and receive data. below is the python code which opens a socket on the localhost @ port 21567: #!/usr/bin/python2 from socket...
6
4091
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
10
5568
by: groups.20.thebriguy | last post by:
socket objects have a little quirk. If you try to receive 0 bytes on a blocking socket, they block. That is, if I call recv(0), it blocks (until some data arrives). I think that's wrong, but I...
8
5977
by: Mark Fink | last post by:
I try to port a server application to Jython. At the moment I use Jython21\Lib\socket.py Currently I do face problems with casting the string "localhost" to the desired value:...
3
4261
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
0
3138
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
6
6438
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
2
2232
by: Sparky74 | last post by:
Hi. Can somebody please help me - I cannot get my TCP client application to close its socket one I attempt a send. It will close the socket fine if I don't call Send or BeginSend. Soon as I do, it...
4
16049
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open...
3
2222
by: Giampaolo Rodola' | last post by:
Hi there, since the socket.socket.family attribute has been introduced only in Python 2.5 and I need to have my application to be backward compatible with Python 2.3 and 2.4 I'd like to know how...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.