PC Review


Reply
Thread Tools Rate Thread

Closing listening socket also closes accepted sockets (?)

 
 
Lenard Gunda
Guest
Posts: n/a
 
      20th Nov 2005
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.Sockets 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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QXNodXJh?=
Guest
Posts: n/a
 
      20th Nov 2005
as the server normally listening network connections:
//preapring network
//...
TcpListener tcpListener = tcpListener.AcceptSocket();
//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


 
Reply With Quote
 
Lenard Gunda
Guest
Posts: n/a
 
      20th Nov 2005
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" <(E-Mail Removed)> wrote in message
news:B8FD416C-E15E-4BC4-997A-(E-Mail Removed)...
> as the server normally listening network connections:
> //preapring network
> //...
> TcpListener tcpListener = tcpListener.AcceptSocket();
> //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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop listening on a socket? ThunderMusic Microsoft Dot NET 10 29th Aug 2007 07:09 PM
Closing listening socket also closes accepted sockets (?) Lenard Gunda Microsoft C# .NET 2 20th Nov 2005 06:49 PM
System.Net.Sockets.Socket closing prematurly =?Utf-8?B?VG9tIE9wZ2Vub3J0aA==?= Microsoft C# .NET 3 21st May 2005 02:57 AM
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" Daniel Microsoft Dot NET 1 15th Mar 2005 11:37 AM
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" Daniel Microsoft Dot NET Framework 3 12th Feb 2005 02:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 AM.