tags:

views:

71

answers:

3

I have two separate socket projects in VS.NET. One of them is sender, other one is receiver. After starting receiver, i send data from sender. Although send method returns 13 bytes as successfully transferred, the receiver receives 0 (zero). The receiver accepts sender socket and listens to it. But cannot receive data. Why?

P.S. : If sender code is put in receiver project, receiver can get data, as well.

A: 

Most likely this is a bug in your code but without seeing the code it's impossible to tell.

However be aware that TCP/IP has no concept of messages, only a stream of data. So it's posisble to send 13 bytes and receive 6 in one read and 7 in the next. Or conversely to send 13 bytes then later send 7 more and on the receiveing side to receive them as a single block of 20 bytes.

John Burton
A: 
Ahmet Altun
Can't only one process open a port on the machine?
kenny
I think sender program is terminated before Receiver program receives the data. Put some sleep after send() in sender program and see it works.
kumar
+1  A: 

I think the problem is that the send application is ending before the receiver can read the data. If you put a Thread.Sleep(1000); after the Send call, the receive application will read the data (at least when I tested it).

Mark Wilkins