How to make a networking game?

i have use

[java]

Server myServer = null;

try {

myServer = Network.createServer(6143);

} catch (IOException ex) {

Logger.getLogger(TestWalkingChar.class.getName()).log(Level.SEVERE, null, ex);

}

myServer.start();

[/java]

for my server and

[java]

Client myClient = null;

try {

myClient = Network.connectToServer(“localhost”, 6143);

} catch (IOException ex) {

Logger.getLogger(TestWalkingCharclient.class.getName()).log(Level.SEVERE, null, ex);

}

myClient.start();

[/java]

for my client…



yes it connected well…



i just can’t find the tutorial how my character on client #1 and client#2 can meet in the one map…

so they can fight each other…



i mean how to make the character load on the client can seen from the other client…

because now i just copy my game to mygameserver and mygameclient…they are the same script with different server and client script above…and surely it loaded it’s own character and map so they not meet each other…

then what should i do, to make them meet each other ?

You will need to send definition messages.



For example make a message called PlayerMessage and in that you put whatever data you need to construct a player on the client.



When you move as a client, you send your position to the server, which then broadcasts that position to the other connected clients.



And on client side, when recieving a move message, you will move the corresponding spatial to that position.



There are alot of stuff that needs to be taken into consideration, for example you need to make sure that all clients know about eachother. A simple way to solve this is that if you recieve a MoveMessage for an ID that you yet not have specified, you send a request message to the server, which then responds with the corresponding data for that player.



Edit: Oh and before you start with that, you will need to make MessageListeners that will be provided the messages from each end.



Take a look at the monkeyzone multiplayer open source example https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:monkey_zone

1 Like

I’m also working on a multiplayer-game atm. today my models finally met each other :wink: this is how i did it:

1)create a server and client class

2)add listeners (in my clients update loop is send a “locationData” message to the server which includes: position, direction, playername/id, current animation)

3)make the server “spread” the messages he gets from the clients ( server.broadcast(…))

4)make the clients “sort” the datas. for this i created an array to storrage the incoming data. whenever the client recieves a “locationData” it is saved its playerdata[ ]

5)create the other caracters and make them move(give them the position/direction/… stored in the playerdata[ ])



hope this helps a bit thou i’m not sure wether this is the ‘best’ sollution.

1 Like

for @perfecticus and @taiten, can you send me how you send your potition etc to server and spread it to all client that connected into server?

or maybe example in the monkey zone ? because i can’t download it.

because i have no idea how to do it…

i confused about are we move first then sent to server then broadcasted…or we not move first then we sent new potition and we get our move from the server broadcast so we can move?



if we use the first method then we got our potition from our movement then we would got again at the broadcasted server, am i wrong?

if you want to download monkeyzone you will need an SVN-checkout program like for example ‘Tortoise SVN’.



For a beginner i’d reccomend to have a look at the JME test files (go in your IDE and File->New Project->JME3->JME3 Tests) you will find many astonishing things there and for example a server-client example.



you may also want to have a look at:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:networking_video_tutorials

watch them all and sending the right packages etc. will not be a problem for you at all.



if you have any questions after having a look at the JME3 tests and the video tutorials let me know.



TaiTen

2 Likes

really thanks for your reply i would learn it… and can i have your yahoo messenger so later we can chatting each other taiten?