Answer the question
In order to leave comments, you need to log in
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();//непонятное число
DataInputStream dIn = new DataInputStream(socket.getInputStream());
String selectedFile = dIn.readUTF();//принимает то, что нужно
File dd = new File(selectedFile);
long size = dd.length();
dos.writeLong(size);
dos.flush();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question