Search code examples
javanetwork-programminggreenfoot

Run a game on two computers?


I am creating a two-sided war game using Greenfoot. I would like to play it with my brother but I would also like my brother to be able to see only one part of the whole map and me too. Hence, I would like my brother to be able to play it on his computer and I to play it on mine.

This is supposed to be a real-time game but I could make it turn-based if it's too hard. How do I connect my mac and my brother's mac so that the game runs simultaneously on both ( I would like it to receive both keyboards input).

I have no experience in networking so I don't know if it's possible.


Solution

  • This communication between your mac and your brother mac could be done using java sockets. You will be the server, and your brother will be the client. You need to open the server with ServerSocket on a specific port and your brother will connect with the help of Socket. You can find more details about implementing a java socket here ( and look at the 3rd chapter named "Simple Example")