Jump to content
  • Advertisement
Sign in to follow this  
yepp_85

networking in a java-game???

This topic is 3608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im new to game-programing and i wanted to learn so I have been trying to make my own bomberman. It wasnt to hard. I created a class that takes care of all the logic like canIMoveThere, isThereABombInFrontOfMe, and so on... and i created a player-class the takes care of the player like playerPos, playerNumberOfBombs and so on... I should also mention that the game is written i Java. Everything is working just fine but now i want to add networking to the game.. So my plan is that one player starts a server on his computer and a friend connects over TCP. The network communication was easy to set up in java and the sever and client has no problem sending data back and fourth my big question is: what should i be sending between the server and client. should the server be in charge of all the logics in the game and just send an image of the game back to the client so the client can draw that on his screen. or should the client send his key-presses to the server and the server send all his key-presses to the client. This means that they both takes care of the game-logic. Ive tried doing this but its not working any good. Does anyone have a good idea have to solve this? is there some standard way of communicating between server-client in a game? //thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Greetings

The logic should be handled by both "clients" themselves. The data send should be the commands that define what logic to render to the screen. It is just a question of data amount and therefore speed.
What logic you want to send depends on you. Someone could argument that serialized logic objects would be the most generic and can easy and fast be converted to game logic and therefore onto the screen, but a serialized object often needs a larger amount of data and therefore communication time. Someone could argue that in todays times the Internet connections are fast enough.
Instead of objects you could use some kind of code, e.g. specific Binary Commands, ASCII Commands or a structure like JSON. These CAN (no must here) be smaller than whole serialized objects and therefore been send faster. But such data structures would need to be parsed/interpreted/converted to game logic and therefore need computation time. Someone could argue that todays computer are fast enough for such work.

... and many possibilities more...


As you can see there is, as always, no "one" answer. I hope I gave two examples with their pros and cons and an idea on what to figure out.
From my point of view, if it is just an example game, a test, a learning game and you are using Java: Utilize serialized logic objects. It is easy to implement, easy to send and easy to use.

Share this post


Link to post
Share on other sites
For a prototype, I recommend looking into RMI (remote method invocation). It allows you to call methods on objects that reside on other computers, so the protocol is plain old Java. No need for baking your own IP-packets from bytes ;)

Share this post


Link to post
Share on other sites
I'm not a pro on this subject, but I've been working on something simmilar myself.

the game has to be tick based to work.

the server will send out a tick every x ms.
the tick triggers the client to run a gameloop.

the client sends every gamerelated user input to the server.
the server validates the input, and sends it back to all clients, at next tick.
the clients executes the input, if it is possible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!