Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET newbie socket problem

Tags:

c#

.net

sockets

I have a C# client/server network program I've written using TCPListener and TCPClient classes. The server is reading everything from the client (small amounts of xml) just fine until I try to send a large file (100k) back to the client.

I'm using stream functions for both client and server with non-blocking socket functions. When I do a socket.SendFile("filename") back to the client, the file is getting cut off - I've set the receive buffer size on the client to well past 100k but it still gets cut off around 25k and the communication between client and server is unreliable afterwords.

My basic question is what happens if data is somehow left in the pipe ? i.e.. will it be read by the next socket.Read... Does every Send call require exactly one and only one Read ? Maybe I'm not giving the client enough time to read the file but their both on the same machine and I've tried sleeping for a few seconds in various places w/o success.

like image 293
Slavko Vorkapitch Avatar asked Jun 12 '26 18:06

Slavko Vorkapitch


1 Answers

It is very possible that you cannot read the entire message through one Read call (perhaps all data has not arrived yet). In network programming, you would often place the call to Read in a while loop and simply Read() until you have received the entire expected message.

like image 131
driis Avatar answered Jun 14 '26 08:06

driis