I use only regular DataInputStream and DataOutputStream in streams for receiving, sending (with reception on the server) to make the game, but it is very slow. > 5 seconds.
Here's how I did it (most of them look like this):
(dos - DataOutputStream)
dos = new DataOutputStream(socket.getOutputStream());
dos.writeFloat(dp.x);
dos = new DataOutputStream(socket.getOutputStream());
dos.writeFloat(dp.y);
dos = new DataOutputStream(socket.getOutputStream());
dos.writeUTF(dp.username);
And for input (this one is on the server) I use:
(dis is DataInputStream, it is in a for loop, so I am for each player)
dis = new DataInputStream(list_sockets.get(i).getInputStream());
x = dis.readFloat();
dis = new DataInputStream(list_sockets.get(i).getInputStream());
y = dis.readFloat();
dis = new DataInputStream(list_sockets.get(i).getInputStream());
username = dis.readUTF();
So, this is very slow, but I do not know why :( Please help?
EDIT: each operation (send, receive, receive) has its own daemon stream.
source
share