472,334 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

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 2377
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
I've said here before that I'm self taught. I have 4 reference books, and they mention listeners and give partial examples, but not one gives me a...
1
by: Fred Mellender | last post by:
When I code: Debug.Assert(false, "this is a message"); it works fine, and out comes the dialog box. When I code Trace.Listeners.Clear();...
2
by: Paul A. Steckler | last post by:
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....
9
by: John J. Hughes II | last post by:
I have a system where my software sits on one server and interacts with another server running MS SQL. My software recieves connects via a socket...
2
by: jasonsgeiger | last post by:
From: "Factor" <jasonsgeiger@gmail.com> Newsgroups: microsoft.public.in.csharp Subject: Multiple Clients, One port Date: Wed, 19 Apr 2006 09:36:02...
0
by: Ben K | last post by:
Is it possible to setup multiple SQL Server "listeners" like Oracle's so that I can have N X M mapping between LISTENERs and DB INSTANCEs? What I...
3
by: breeto | last post by:
If you've configured .NET Remoting to use more than one channel of the same type, for example two TcpClientChannels with unique names, when you...
0
by: Robinson | last post by:
At present I'm generating a log file during program execution by creating a console log trace and sending it to an external file thus: ...
1
by: jcprince | last post by:
Hi Not sure I can do what I'm trying to do without using a 3rd party component like Dart. I need to build a windows service to create a socket...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.