473,686 Members | 2,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.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 "BeginAccep t". 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(Socke tShutdown::Both );
Thread::Sleep(2 50);

m_ServerSocket = NULL;
Thread::Sleep(5 00);

mf_ChangeButton StatusTo( ConnStatus::CON NECT );
catch(Exception *exp) {
// Programda hata durumunu göster

Below are the options of my sockets
Server Socket:
SetSocketOption (..., SocketOptionNam e::ReuseAddress , true);
SetSocketOption (..., SocketOptionNam e::KeepAlive, true);
SetSocketOption (..., SocketOptionNam e::DontLinger, true);
Client Socket:
SetSocketOption (..., SocketOptionNam e::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 2596

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

Similar topics

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 import * from time import time,ctime HOST ='' PORT = 21567
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: Connect Receive response Send Connect ACK
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 don't want to argue that. I would like to create a subclass of socket that fixes the problem. Ideally, something like: class new_socket(socket): def recv( self, bufsize, flags=0 ):
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: D:\AUT_TEST\workspace\JyFIT>jython fit/JyFitServer2.py localhost 1234 23 localhost Traceback (innermost last): File "fit/JyFitServer2.py", line 146, in ?
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 receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
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 System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Runtime.Serialization.Formatters.Binary;
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 fairly common idiom (at least in the Java/UNIX/Win32 worlds) where a socket connection is established and the program then utilises two threads: one dedicated to reading from the socket and the other one concurrently writing to the socket - both using...
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 won't close. Thank you using System; using System.Collections.Generic;
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 the socket again, the bind fails because the port is still in use. When I execute the code in "debug" mode, the problem never occurs. When I execute the same code in release mode, the problem appears about 20% of the time. Here's the code:
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 could I determine the family of a socket.socket instance which may be AF_INET or AF_INET6. Is there some kind of getsockopt() directive I could use? For now I've been able to determine the family by using: # self.socket = a connected...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 we have to send another system

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.