473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

.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 2566

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

Similar topics

1
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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
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
tracyyun
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...

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.