473,758 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Closing listening socket also closes accepted sockets (?)

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 managed).

I create a server socket, and then listen on it. I then accept a new
connection from that server socket. If I now close the server socket, it
also closes the accepted connection as well, automatically. This feels
stupid.

In C++ closing the listening socket has no effect on the accepted socket. In
fact I recall seeing some examples, which did just like this.

However, in C#, there seems to be some "mysterious " connection between the
two.

I read the documentation in MSDN Library, and tried searching for this
behaviour. I even looked at the System.Net.Sock ets namespace with Reflector,
but did not come across anything usefull. Does anyone know why C# (.NET)
behaves like this, and how it could be made to behave the way classic
winsock behaves?

I would like to close the server socket after the client has connected,
because I do not want to listen any longer for new connections, just
communicate with that single client.

Thanks for any help

Lenard Gunda
Nov 20 '05 #1
2 3496
as the server normally listening network connections:
//preapring network
//...
TcpListener tcpListener = tcpListener.Acc eptSocket();
//got connection here
//as soon as the server program jumps out of the above line
//the server is NOT accepting any new connetions

this is the same 'sematic' as ya wish it to be, isnt it?
regards
Nov 20 '05 #2
Hi,

I am not sure this is what I want. I do not use the TcpListener class, I
prefer more direct control over my sockets and use only the Socket class
directly.

I know that if I do not call accept again, I will never receive a
connection, but I would like to close the listening socket. But as soon as I
call Close() on the server socket, it also closes all related sockets, ones
that were opened through that particular server socket. And I do not want
this to happen.

And as I said, this is not the usual behaviour I have seen from sockets when
working with them in C++.

Thanks
-Lenard Gunda

"Ashura" <As****@discuss ions.microsoft. com> wrote in message
news:B8******** *************** ***********@mic rosoft.com...
as the server normally listening network connections:
//preapring network
//...
TcpListener tcpListener = tcpListener.Acc eptSocket();
//got connection here
//as soon as the server program jumps out of the above line
//the server is NOT accepting any new connetions

this is the same 'sematic' as ya wish it to be, isnt it?
regards

Nov 20 '05 #3

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

Similar topics

8
9287
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 python wrapper module for sockets, and found that the close command doesn't actually call the underlying close! this didn't seem right, so i added it, and my code now works simply and as expected. def close(self):
9
3616
by: User | last post by:
Hi, I tried to find the information over the internet but didn't find any answers. I'm looking for a server side code example of winsock accepting many clients. I know that in VB.NET it is not implemented like in VB6. What I've done is one client per socket. Meaning that each client used a different port on the server, but I find it annoying.
1
3794
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 after i send data into it? I simply want to open socket, send data, close socket and have the server just handle one client thread to recieve connection, recieve data, and close socket
3
2396
by: ssantamariagarcia | last post by:
I am trying to program a server in C for UNIX to get a kind of "bridge" between the clients of a port A and the clients of a port B. For that, I create 2 processes: one that listen the requests of port A clients and another for the Port B ones. In each process, when a connetion service is required, after accepting , the value of the socket generated is added to a set of sockets. This set keeps on listening on each socket for new...
4
7090
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer; private Socket socket; private Socket accSocket; private System.Windows.Forms.Button button2;...
3
2829
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 client connects, the connection is NEVER to be closed by the server. The client will send messages as necessary. After each message the server is to send an acknowledgement back to the client. That is the client's indicator to send the next...
8
11018
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 socket during a read and I get the following error: <error_msg> An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll Additional information: The I/O operation has been aborted because of
4
2768
by: Funke | last post by:
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?
10
5184
by: ThunderMusic | last post by:
Hi, I'm currently working with sockets. I accept connections using m_mySocket.Listen(BackLogCount); But when I want to stop listening, I shutdown all my clients and call m_mySocket.Close(), but it always raise a OnConnect event (actually, it calls the callback function as if there was a new connection attempt) and I receive a ObjectDisposedException as soon as I do m_mySocket.EndAccept. Does anyone have any idea of what I could do about...
0
9299
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,...
0
9908
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9740
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 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...
0
8744
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, and deployment—without 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...
0
6564
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();...
0
5175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3832
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
3
3402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2702
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.