How do I listen to a random number of ports with one socket?

E

Egil Hansen

Hello

I'm trying to build a application, that will use one socket to send a
lot of queries out to different servers (game servers), and have
another socket handle the replies. E.g. I don't want to create a
socket for each of the queries I send out.

My problem is, that I cant figure out how to make my listening socket
listen to more then one port at the time. All the traffic is in UDP
packets.

Any input is much appreciated. Thanks, Egil.
 
E

Egil Hansen

Hi Vadym

I'm trying to build a web based game server browser. If say, for
instance, that there is 5 users online, and they each want to query 10
game servers for info (server name, map, players online, player names
etc.), the straight forward method would be to instantiate 5 sockets (1
socket per user), and let each socket query the 10 game servers one at
the time.

This approach is easy, but not very resource friendly nor fast. If one
of the servers is not responding very fast, the user might end up
waiting a few seconds before the page refreshes.

So to speed things up, I decided to try using a single static socket
for sending out all the queries, and then have socket for handling the
replies. That I can't figure out how to do though.

Another way to go about it would be to simply instantiate one socket
per server that is to be queried, and using threading. That however,
would result in there being created many sockets, that would only be
used shortly. That's certainly not very good on the resources, but
would probably be faster then simple implementation.

Regards, Egil.
 
A

Adam Clauss

Maybe you could move your code for querying servers into a Windows Service
or something?

This way, only that one "user" (the service) has a set of sockets querying
the game servers.

Then, have some sort of communication setup between the service and your web
app. When a user goes to your website, the web app queries the service for
the current status of the servers.

HTH
 
E

Egil Hansen

Hi guys

Thanks for the input. I ended up using a ThreadPool and a "SocketPool".
That should keep my resources usage under control.
 

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