I suggest not using full serialization for simply primitives. use DataInputStream
and the like instead:
dostream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
distream = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
Then read with:
ballx=distream.readInt();
bally=distream.readInt();
and write as:
dostream.writeInt(ballx);
dostream.writeInt(bally);
Also I suggest you not sleep awaiting data on both sides. Sleep on one and let the second simply await for a full set of data before transmitting by cutting out the Thread.sleep()
there.