send multiple file over TCP with C# using TcpClient

后端 未结 3 602
醉梦人生
醉梦人生 2021-01-28 11:25

I\'m trying to send multiple files over TCP using C# TcpClient, for a single file it works great, but when I have multiple files, it sends only the first one.

Here is my

相关标签:
3条回答
  • 2021-01-28 11:46

    you must close the stream after sending a file.

    http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.getstream%28v=vs.71%29.aspx

    "Note You must close the NetworkStream when you are through sending and receiving data. Closing TcpClient does not release the NetworkStream."

    0 讨论(0)
  • 2021-01-28 11:53

    Short answer for this is, do it like ping-pong, send first file, let client reply, send again another file, let client reply and so-on.

    0 讨论(0)
  • In your sending code, you've got a loop where you're sending multiple files. On the receiving side, I don't see a corresponding loop.

    You could send the number of files that are about to be sent, and have the client loop that many times. You could also send something after the end of each file, which would indicate "Here comes another file" or "I'm done, close everything now".

    0 讨论(0)
提交回复
热议问题