469,927 Members | 2,022 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Multiple listeners on a TCP/IP port?

I need to write a TCP/IP server in C# that can handle multiple connections.
My first try was to use TCPListener instances in multiple .NET threads.
Of course, I got an exception from System.Net.Sockets about multiple
sockets on the same port. This happens even with a single listener in
multiple
Win32 processes.

Will I get better results by using a Socket instance with BeginAccept?
Should I run multiple threads, or do the asynchronous callbacks already
give me enough concurrency?

-- Paul
Jul 21 '05 #1
2 2243
On 2003-11-26, Paul A. Steckler <st***@acm.org> wrote:
I need to write a TCP/IP server in C# that can handle multiple connections.
My first try was to use TCPListener instances in multiple .NET threads.
Of course, I got an exception from System.Net.Sockets about multiple
sockets on the same port. This happens even with a single listener in
multiple
Win32 processes.

Will I get better results by using a Socket instance with BeginAccept?
Should I run multiple threads, or do the asynchronous callbacks already
give me enough concurrency?

-- Paul


My personal preference is to use a Socket instance and the async methods
- but, your problem is caused by a misuse of the TCPListener class. You
only need one instace of the TCPListener class. You accept connections
using ether the AcceptTcpClient or AcceptSocket methods. What get's
returned from those methods is a new socket or tcpclient object that
then will act as your communications channel.

You may want to have a look here for some information on sockets in
..NET:

http://msdn.microsoft.com/library/de...consockets.asp

Anyway, there are some code examples, etc. That is of course, not a
complete reference on network programming, but it maybe a useful
starting point.

--
Tom Shelton
MVP [Visual Basic]
Jul 21 '05 #2
"Tom Shelton" <to*@mtogden.com> wrote in message
news:OT***************@TK2MSFTNGP09.phx.gbl...
My personal preference is to use a Socket instance and the async methods
- but, your problem is caused by a misuse of the TCPListener class. You
only need one instace of the TCPListener class. You accept connections
using ether the AcceptTcpClient or AcceptSocket methods.


Oops, right.

I've got my code working fine now, thanks.

-- Paul
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hal Vaughan | last post: by
1 post views Thread by Fred Mellender | last post: by
2 posts views Thread by Paul A. Steckler | last post: by
9 posts views Thread by John J. Hughes II | last post: by
2 posts views Thread by jasonsgeiger | last post: by
3 posts views Thread by breeto | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.