How do I send multiple files to tcp at the same time in c sharp?


I have a tcp client - server implementation running in the same program, on different background worker threads. There will be instances of this program on multiple computers so they can send and receive files between each other. I can send files sequentially between computers using network stream, but how would I send multiple files at the same time from computer A to B.

Sending multiple files over one connection ( socket ) is fine, but having multiple network streams sending data to a client, the client doesn't know which chunk of data is apart of which file ?

Would it be possible for the client to connect twice to the server (on a difference port, as a 'random'/ unused port is assigned to the connection) and then each connection have its own stream, allowing 2 files to be sent at the same time?

Thanks for your time and effort.

You could do that, but I don't see the benefit. Unless the each connection is throttled somewhere down the line, you are essentially incurring twice the overhead of your I/O operations.

It's the same as writing a file to a disk, just because you split it to two threads doesn't mean it will be faster, because the disk can only be written to at one time. You might actually see a slower response time.