I am building distributed game using java based on tcp protocol.When I send multiple packets from one client to the other one, the receiving part only gets the very first packet again and again.Could anyone give any hint? Thanks beforehand.
Here is the code in receiving side: Note MazePacket is a class which implements serializable MazePacket packetFromClient;
/* stream to write back to client */
ObjectOutputStream toClient = new ObjectOutputStream(socket.getOutputStream());
/* stream to read from client */
ObjectInputStream fromClient = new ObjectInputStream(socket.getInputStream());
while ((( packetFromClient = (MazePacket) fromClient.readObject()) != null) && listening)
{
if (packetFromClient.type == MazePacket.MOVE_FORWARD || packetFromClient.type == MazePacket.MOVE_BACKWARD ||
packetFromClient.type == MazePacket.TURN_LEFT || packetFromClient.type == MazePacket.TURN_RIGHT ||
packetFromClient.type == MazePacket.FIRE)
{
/* update your local clock */
int counter=0;
int size=packetFromClient.timestamp.length;
System.out.println(" I am receiving packet with the timestamp:"+Arrays.toString(packetFromClient.timestamp));
synchronized(Mazewar.class) {
for(int i=0; i<size;i++) {
Mazewar.VectorClock[i]=Math.max(Mazewar.VectorClock[i],packetFromClient.timestamp[i]);
counter=counter+packetFromClient.timestamp[i];
}
}
/* tag the packet and put in queue */
packetFromClient.tag=counter;
ActionSequencer.ActionList.add(packetFromClient);
}
/* wait for next packet */
continue;
}