473,385 Members | 1,324 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,385 software developers and data experts.

Closing Sockets

Assume that in C#, I create a server socket (listener) and code to start
new threads with each connection using BeginAccept(). After some time,
I have three threads running, each with their own client socket
connection. If I close the listener socket, will the client sockets
also shut down? Or do I need to manually shut these down as well?
Oct 26 '06 #1
4 2740
"Funke" <ne********@dafunks.comwrote in message
news:12*************@corp.supernews.com...
Assume that in C#, I create a server socket (listener) and code to start
new threads with each connection using BeginAccept(). After some time, I
have three threads running, each with their own client socket connection.
If I close the listener socket, will the client sockets also shut down?
No, they will not be.
Or do I need to manually shut these down as well?
Yes, you do need to. The connected sockets are completely independent of
the listening socket.

Pete
Oct 26 '06 #2
Peter Duniho wrote:
"Funke" <ne********@dafunks.comwrote in message
news:12*************@corp.supernews.com...
>Assume that in C#, I create a server socket (listener) and code to start
new threads with each connection using BeginAccept(). After some time, I
have three threads running, each with their own client socket connection.
If I close the listener socket, will the client sockets also shut down?

No, they will not be.
>Or do I need to manually shut these down as well?

Yes, you do need to. The connected sockets are completely independent of
the listening socket.
Is there any way to get a list connected sockets that originated from the
listening socket using the listening socket instance?
Oct 26 '06 #3
"Funke" <ne********@dafunks.comwrote in message
news:ko*******************@bignews1.bellsouth.net. ..
Is there any way to get a list connected sockets that originated from the
listening socket using the listening socket instance?
In .NET, not as far as I know. Typically, an application would maintain its
own list of connected sockets that are related to a specific listening
socket.

I don't think there's even any reliable way to do it outside of .NET either.
The only real connection between the listening socket and sockets connected
by that listening socket is the port number, and since one could close a
listening socket and later open a new one with the same port number, even
enumerating all your open sockets and comparing the port number doesn't
necessarily tell you that those open sockets were connected using a specific
listening socket.

IMHO, the correct thing to do is simply maintain your own list of related
sockets, so that you can perform whatever operations on them are needed as
appropriate.

Pete
Oct 26 '06 #4
Your client sockets should be closing themselfs down using your protocol.
After the client finishes last send, it should shutdown send side. After it
receives 0 from read, it can close socket as now both sides of socket are
done. You should only force a Close as a last resort if you need to force
an app down and don't care what the clients happen to be doing.
List<Socketis one way to go to keep your scoreboard. Normally, you have
some other "Client" object that maintains the state of that client - your
socket object would just be contained in that class so a List of <Client>
may be the way to go in that case.

--
William Stacey [C# MVP]

"Funke" <ne********@dafunks.comwrote in message
news:ko*******************@bignews1.bellsouth.net. ..
| Peter Duniho wrote:
| "Funke" <ne********@dafunks.comwrote in message
| news:12*************@corp.supernews.com...
| >Assume that in C#, I create a server socket (listener) and code to
start
| >new threads with each connection using BeginAccept(). After some time,
I
| >have three threads running, each with their own client socket
connection.
| >If I close the listener socket, will the client sockets also shut down?
| >
| No, they will not be.
| >
| >Or do I need to manually shut these down as well?
| >
| Yes, you do need to. The connected sockets are completely independent
of
| the listening socket.
|
| Is there any way to get a list connected sockets that originated from the
| listening socket using the listening socket instance?
Oct 27 '06 #5

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

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
3
by: Anand Pillai | last post by:
I recently noted that urllib2.urlopen(...) for http:// urls does not make an explicit call to close the underlying HTTPConnection socket once the data from the socket is read. This might not be...
4
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to...
1
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket...
5
by: Alper AKCAYOZ | last post by:
Hello Developers, I have developed Server and Client applications that are communicating by TCP/IP sockets. My application is developed on Visual C++ .NET Standard v2003 Windows Forms. When one of...
3
by: Tom Opgenorth | last post by:
I'm experiencing a problem with sockets, and I'm really hoping someone can help me, please and thank you. I've written a TCP Server, which listens on a port for an incoming connection. When the...
2
by: Lenard Gunda | last post by:
Hi, I have the following problem when I am working with sockets in C#. I do not remember running into the same problem some while ago, when working with sockets from C++ (using native code, not...
2
by: Macca | last post by:
Hi, I am writing an app that will have a socket server to listen for and process data from 20+ clients. These clients will send data aproximately every 400-500ms. I was wondering if it is...
8
by: Dinsdale | last post by:
I am trying to write a Tcp "Server" that opens a class that wraps a tcp socket when a new connection is made (Listener.AcceptSocket()). Everything is going swimmingly except when I try to close the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.