Hi all,
For my uni assignment I have to make a multiplayer pac man game using Java. I'm using a client/server approach and have made all the main classes.
I have 3 classes. GameClient, GameServer and Listener.
The Listener class uses a serverSocket to listen for clients requesting a connection. When a client makes a request the serverSocket creates a new Socket and creates a new GameServer, passing in the new Socket as a parameter. The GameClient and GameServer then communicate over this
Socket and it works fine. The Listener also increases the port it is listening on by 1.
The problem occurs when I try to join with a second client. The second GameClient requests a connection from the Listener. This connection is created using the new port which is 1 more than the port the first GameClient is using and a new GameServer is set up to handle this second client. However even though the servers are running on different ports they seem to communicate with each other, so each client is interfering with the other.
For example, if I move left 5 spaces in the first client the pac man moves 5 spaces left. If I then go to the second client, it has also moved 5 spaces to the left, even though I haven't told it to do so.
Is there any way that I can make sure the Sockets don't communicate with each other?
For my uni assignment I have to make a multiplayer pac man game using Java. I'm using a client/server approach and have made all the main classes.
I have 3 classes. GameClient, GameServer and Listener.
The Listener class uses a serverSocket to listen for clients requesting a connection. When a client makes a request the serverSocket creates a new Socket and creates a new GameServer, passing in the new Socket as a parameter. The GameClient and GameServer then communicate over this
Socket and it works fine. The Listener also increases the port it is listening on by 1.
The problem occurs when I try to join with a second client. The second GameClient requests a connection from the Listener. This connection is created using the new port which is 1 more than the port the first GameClient is using and a new GameServer is set up to handle this second client. However even though the servers are running on different ports they seem to communicate with each other, so each client is interfering with the other.
For example, if I move left 5 spaces in the first client the pac man moves 5 spaces left. If I then go to the second client, it has also moved 5 spaces to the left, even though I haven't told it to do so.
Is there any way that I can make sure the Sockets don't communicate with each other?