I have stucked for 4h already with the sockets, the way I am using is is that there is only one application as client and server, once the client connect it is opening the t
You can't mixed buffered and unbuffered streams/readers/writers on the same socket. You will lose data in the buffers. Use the same stream pair for the life of the socket. In this case I would use DataInputStream
and DataOutputStream
, and the readUTF()/writeUTF()
methods for the messages and filenames. You will also need to send the file length ahead of the file, unless the file is the last thing sent over the connection: otherwise the peer won't know when to stop reading the file and go back and start reading messages again.