K
K
Konstantin17062015-09-22 10:34:58
Java
Konstantin1706, 2015-09-22 10:34:58

Working with sockets, why am I getting strange data (Java)?

Good afternoon. There is a client-server application. The client sends the address of the file, the server receives and sends the size of this file, but the client receives the wrong number at all (it is either a negative large number or a large positive one), as if it were some kind of garbage.
Customer.

DataInputStream din = new DataInputStream(sock.getInputStream());
DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
dos.writeUTF("1.txt");
long fileSize = din.readLong();//непонятное число

Server.
DataInputStream dIn = new DataInputStream(socket.getInputStream());
String selectedFile = dIn.readUTF();//принимает то, что нужно
File dd = new File(selectedFile);
long size = dd.length();
dos.writeLong(size);
dos.flush();

If anyone knows, tell me. Thank you very much for your attention.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lyeskin, 2015-09-22
@lyeskin

And the number exactly gets into the size variable correctly?

K
Konstantin1706, 2015-09-22
@Konstantin1706

exclusively checked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question