I have an application that I have written for my application distributed throughout the company to send data to me through our Windows 2003 server (running IIS 6.0). Small t
Your telnet example is somewhat contradictory to the behaviour of the code that you describe - if you are ever able to get anything on the server, the "telnet <hostname> <portnumber>" should get you to a blank screen pretty quickly (on windows machine in the CMD prompt that is). So, this is the first strange thing - best debugged with wireshark, though.
Code-wise, I think it may be problem with this inner line on the server:
... while ((0 < len) && (ns.DataAvailable == true));
You say that you want to loop while you were able to read something and while there is some data available.
However, it may be that the second segment has not made it to the server yet, so there is no data available yet, so you are falling out from this loop.
You should loop receiving data while you are reading something and while there has not been any read error - this guarantees that even on the slow links you will reliably receive the data.
A side note:
I notice your protocol is request-response-request-response type. It works well on the LAN, however if you need in the future to make it work over the high-round-trip-time links, this will become a big performance bottleneck (MS SMB protocol used for filetransfers or TFTP works in this fashion).
(Disclaimer: I didn't code in C# much, so might have been wrong in the interpretation of "DataAvailable()" method, take this FWIW).
Edit: probably my answer above would need to be corrected according to your protocol - i.e. you'd need to first read the length of the file, and then read the file - since if you take it verbatim it will break the way you designed it completely.
That said, with TCP one should never assume the number of write() operations on the sender side is the same as number of read() operations on the receiver side - in some cases it may be the case (no packet loss, no Nagle) - but in the general case it would not be true.
You should precede the sent content with the length of that content. Your loop assumes that all of the data is sent before the loop executes, when in reality your loop is executing as the data is sent. There will be times when there is no data waiting on the wire, so the loop terminates; meanwhile, content is still being sent across the wire. That's why your loop is only running once.
If I read your code correctly, you've basically got (sorry for the c-style - I'm not good with c#:
do { socket = accept(); read(socket, buffer); }while(not_done);
If I'm correct, then it means you need... a little more in there. If you want it to be serialized, reading each upload in sequence, you'll want a second loop:
do { socket = accept(); do { read(socket, buffer); not_done_reading=...; } while (not_done_reading); }while(not_done);
If you want to read multiple uploads simultaniously, you'll need something more like:
do { socket = accept(); if( !fork() ) { do { read(socket, buffer); not_done_reading=...; } while (not_done_reading); } }while(not_done);