473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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
3 1930
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim Kipp | last post by:
Hi I am writing a simple server to monitor ports. The problem is I don't know how to make it listen on multiple ports. It creates the first socket, listens, than accepts and of course the accept...
9
by: mBird | last post by:
I wrote a service that listens for broadcast messages from my firewall (UDP snmp trap messages) and parses and puts the data in an database. I'd also like to write an app that is a simple form...
1
by: HABJAN ®iga | last post by:
Hello, how can i bind a socket for listen on some port, and all addresses : In the sample i bind myself to localhost(127.0.0.1) on port 5500. It works fine when connecting to localhost, but if...
0
by: Crirus | last post by:
I have a Socket server. Any value I give to the listener.Listen(1) socket, seems that it accept any connection request... why's that? I set a sleep on send thread in order to delay the response...
3
by: D. André Dhondt | last post by:
In VB.NET 2003, is there a way to create a System.Net.Sockets.UDPClient to listen to any address AND any port? I can get it to listen to any address, but only if I specify a port (for example,...
1
by: Yofnik | last post by:
I am writing an application that simulates a TCP device that only accepts one connection at a time. For my application, I would like connection requests to fail if one already exists. So far I have...
1
by: =?Utf-8?B?aXdkdTE1?= | last post by:
Hi, i have a socket that i use to listen for a connection. there can be any number of connections. when testing my socket, it sees the first connection, then no others. i call the BeginAccept()...
7
by: silverburgh.meryl | last post by:
Hi, I read the following code which open a server socket for client request. However, i would like to know how can I change it so that i just listen for client requestfor 10 seconds, after...
2
by: Jason | last post by:
Hello I'm about ready to attempt writting a simple TCP server in C# in which all I need to do is send out some data to a particular IP and port, and the end device will send it back to me. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.