I have a multi-threaded server that processes client requests and creates new threads for each connected one. This works great, and I can send text messages back and forth to the server without any problems. Like a chat system.
Now I mean a way to send files through these client connections to the server, but every single example that I see in java always has a hard-coded file name on the server / client side, but I want to set the flexibility for myself. And I would be very pleased if he could not only receive files, but also receive text messages on the same port simulatanously.
I have an idea that at the moment there is a “text” message port, tells the server that the file will be sent from the client, and then the server opens the “file transfer” port, only for transferring files, Thus, the “text” port could specify a name, etc. File. And another port can send files quite happily, without interruptions.
Does anyone know a better way to do this? I really don't want to use two ports, this seems a bit messy. I would prefer to make a separate server-side thread to deal with file transfers, as well as deal with a text message at the same time, if possible?
Thanks in advance, I hope I was clear enough :)
source share