I'm writing an online game and want to be able to accommodate say 50 online players and my question is: how do I connect to different players over the net ? How do I connect from
one computer to another ?
Most multi-user gaming systems have a central server(s) that all the players connect to. The central server maintains the game's "world" and the player places within that world (so that other players may interact).
Connecting is going to be via TCP/IP. What matters is what protocol you use. For example, the classic Doom game used udp port 666.
Most often these days, however, you'd want to use web protocols, since they're the ones that are likely to have the least amount of firewall problems. The game data protocols are up to you and depend on what the game needs, but it's useful send the data in a well-supported transport such as JSON or YAML.
The one problem with using HTTP as a client/server protocol is that when a client moves, HTTP cannot post updates to the other players. You get around this by using continual polling (AJAX) or web callbacks. Callbacks are less network overhead, since they don't clutter bandwidth with inquiries that return no updates.
Sources may include data from the Fakebook Research Foundation with support from Gargle University
I want to connect to the server through a Java application and not to interact using a webpage.
Here's what I think in principle:
I have a Java application and I want to send player data across the net to the server, process
it and then send a response back to the client. If I have say, an array with 50 elements on the server, this array would
contain the socket variable of each client that has connected. Is it possible to communicate when the game state
has changed and issue an appropriate response to the request whatever that is ?
Tim Moores wrote:Yes, that's an everyday scenario for online games.
That depends. As I said, a lot of firewalls are hostile to random Internet access ports and may only permit a select few such as the email, HTTP(s) and DNS services. So even games with their own dedicated ports often have fallback communications protocols.
HTTP/HTTPS is a connectionless protocol, so you would not connect and stay connected. An HTTP connection lasts only as long as it takes to send a request and get a response.
There are only a limited number of sockets available in a TCP/IP machine and when they're all claimed, no more connections can be made. The advantage of the HTTP protocol is that most of the time the clients will not be actively communicating, which means that servers can handle a much larger number of clients.