P2P multiplayer game

Hello,
I’m trying to implement a very simple P2P multiplayer game for two players, but I don’t know how the game logic should be synchronized. For this to work I need one game to be the master and one game to be the slave, so I need some kind of “contract” between those two games that from now on one game is run by the other. However, I don’t know how to approach this.

Thanks for any idea.

PvP or P2P?

(Player-versus-Player or Pay-To-Play)

He said this:

very simple P2P multiplayer game for two players

P2P is peer-to-peer, as in, instead of the players connecting to a remote server, one player acts as a host, and the other as a client.

Yes, I mean peer-to-peer, so that a multiplayer game is possible without central remote server.

You may want to look into this: https://code.google.com/p/jnmp2p/
I’m not sure if it’s any help to you, I’ve never used and know very little about it.

Thanks. My objective is not to implement a professional multiplayer game, but to understand and implement some basic multiplayer functionality.

I think that even in a P2P network it could make sense to implement the server separately from the game, because then the whole game loop and logic can run within the server. Finally the server doesn’t care if one client connects from a remote host or from the localhost, so both clients could run the same kind of server locally. When one client plays alone, he uses his local server but if he plays together with someone else he either waits for someone to connect to his server or connects to someone else’s server. Does this make sense?