By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Multiple listeners on a TCP/IP port?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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.