By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,463 Members | 1,528 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,463 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Apr 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Apr 1 '06 #2

P: n/a
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

--
Adam Clauss
"Egil Hansen" <ru******@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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.

Apr 2 '06 #3

P: n/a
Hi guys

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

Apr 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.