Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Connecting from one computer to another

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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 ?

Thanks

FC.

 
Saloon Keeper
Posts: 24339
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 7111
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That presents a bunch of difficulties. Most often, the communication is done through a central server.
 
Tim Holloway
Saloon Keeper
Posts: 24339
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that similar questions have been asked here before, so you might want to search the forum and see what was said.
 
Pete Bull
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7111
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's an everyday scenario for online games.
 
Tim Holloway
Saloon Keeper
Posts: 24339
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Tim Moores
Saloon Keeper
Posts: 7111
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
None of that changes the fact that it's an everyday scenario, and can be implemented. It's a given that one needs to consider ports and protocols.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic