471,348 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Listening on multiple ports

I am trying to write a vb.net socket application which listens for clients on two ports simultaneously. Is it possible to do so and how can this be done.

Please help.
Jun 27 '08 #1
5 4167
On Jun 26, 11:33*am, rome ez wrote:
I am trying to write a vb.net socket application which listens for clients on two ports simultaneously. Is it possible to do so and how can this be done.
Given that you're writing it in VB.NET, I'm not entirely clear why
you're posting on a C# newsgroup.
However, I'd just create two TcpListeners and call
BeginAcceptTcpClient on each of them.

Where are you having difficulties?

Jon
Jun 27 '08 #2
rome ez wrote:
I am trying to write a vb.net socket application which listens for clients on two ports simultaneously. Is it possible to do so and how can this be done.

Please help.
If you can do it with one, you can do it with two. You instantiate a socket (or
more likely a TcpListener), start it listening. Then repeat.

Typically there is some kind of while loop involved with listening for client
connections. So my personal approach would be to create a class which manages
each socket within its own thread. (A plus which may or may not matter to you
is that you then have the option within your loop to use the simple synchronous
methods which block immediately, such as AcceptSocket().) But what have you
actually tried that is not working and where does the difficulty occur?

(This is not a VB news group, however. Examples you get here will most likely
be in C#. If your problem is syntax related you might consider moving to a VB
group.)

Hope this helps,
-rick-
Jun 27 '08 #3
rome ez wrote:
I am trying to write a vb.net socket application which listens for
clients on two ports simultaneously. Is it possible to do so and how
can this be done.
Obviously that is possible.

The easiest approach is possible just two threads each listening
on one port.

Arne
Jun 27 '08 #4
On Jun 26, 6:33*am, rome ez wrote:
I am trying to write a vb.net socket application which listens for clients on two ports simultaneously. Is it possible to do so and how can this be done.

Please help.
Hi,

This is a C# NG, you should ask VB question in the correct group.

Yes, you can do it, just create two threads with the correct port
number,
Each connection should also generate a new thread, this will let you
have multiple clients for a port at the same time
Jun 27 '08 #5
On Thu, 26 Jun 2008 03:33:33 -0700, rome <ezwrote:
I am trying to write a vb.net socket application which listens for
clients on two ports simultaneously. Is it possible to do so and how can
this be done.
In addition to all of the other replies (which all accurately explain that
dedicating a single thread to each listening socket, plus one thread per
connection), I will point out that the "simplest approach" is only
suitable for relatively small numbers of listeners and connections. Once
you get into the hundreds of connections, you'll want to switch to
something more efficient, which in .NET is basically the asynchronous
methods (i.e. the methods that start with "Begin..." and "End...")

Pete
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jim Kipp | last post: by
5 posts views Thread by lazydb2dba | last post: by
3 posts views Thread by ssantamariagarcia | last post: by
6 posts views Thread by kai | last post: by
3 posts views Thread by tshad | last post: by
5 posts views Thread by =?Utf-8?B?SmVzc2VlIEhvbG1lcw==?= | last post: by
27 posts views Thread by cmdolcet69 | last post: by

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.