Pregunta

I am making a program that sends a file over TCP from the client to server via the IOUtils by copying the fileinputstream to the outputstream in the client and copying the input stream to fileoutputstream in the server. But for this to work, I have to close the streams at the end of the file transfer and after that, I cannot send another file. So is there a way to send multiple files using this method?

¿Fue útil?

Solución

Common methods for sending multiple messages in one connection are

  • sending the length of the message (here: file size), so the remote party knows when to stop reading by counting bytes
  • signalling the end of data by sending a special string that the file cannot contain

You probably are better off with the first one.

Alternatively you could consider using zip file input and output streams; they can contain several independent file entries

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top