473,513 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2477
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
2995
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 good, clear example of setting up a listener,...
1
1846
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(); Debug.Assert(false, "this is a message"); No message...
2
5338
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. Of course, I got an exception from...
9
1969
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 layer on the internet and does it's thing with the...
2
7096
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 -0700 I'm been working with sockets for a...
0
1488
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 want is to partition access to one database, say...
3
14454
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 want to create a proxy to a remote object how do you...
0
972
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: Debug.Listeners.Add(New...
1
3617
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 connection on an IBM mainframe using an IP and port...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7525
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...
0
5685
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,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3233
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...
0
1594
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 ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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...

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.