Listening on multiple ports

R

rome ez

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.
 
J

Jon Skeet [C# MVP]

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
 
A

Arne Vajhøj

rome said:
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
 
R

Rick Lones

rome said:
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-
 
I

Ignacio Machin ( .NET/ C# MVP )

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top