Block a receive call

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello:
I have an strange problem. i am new in sockets, and i'm developing a
client-server application. My client sends information to the server, and it
works. The server receives the information and sends an ACK to the client,
and it works too.
But the problem is that if the client "arrives" to the receive call before
the server sends the ACK, the client doesn't block, go on and receive
nothing...
The more strange thing is that it works in the server. It waits for the
information from the client, and if the information from the client arrives
later than the server arrives to the Receive call, the server waits.
i have the same call in both, this is the code:
---SERVER---
byte [] buf = new byte[1024];
while(true) {
try {
bytesLeidos = nuevoSocket.Receive(buf);
}
}

---CLIENT---
int longitud = socket.Available;
bufferLectura = new byte[longitud];
int resultado = socket.Receive(bufferLectura);


When i create the socket, in the server and in the client i define the
property Blocking of the Socket to TRUE.

Please help me, i am near to finish this application and can't do it until
it stupid thing works.
Thanks for the help.
Bye.
 
nuevoSocket.Receive(buf);

-->The remark from .net framework sdk 1.1 class library:

If no data is available for reading, the Receive method will block until
data is available. If you are in non-blocking mode, and there is no data
available in the in the protocol stack buffer, the Receive method will
complete immediately and throw a SocketException. You can use the Available
property to determine if data is available for reading. When Available is
non-zero, retry the receive operation.

So I suggest you read the System.Net.Sockets.Receive() method's remark very
carefully.And the following url was point to a sample from microsoft(Both c#
and vb.net sample code are availd for you!)

http://www.microsoft.com/downloads/...f8-033d-420b-a3b1-3074505c03f3&displaylang=en

You will find a folder named "Advanced .NET Framework (Networking) - Use
Sockets" after you intalled the 101 samples.And I am sure you will find out
how to solve your problem.Good luck.

-->I can not find a better example of socket programing so far. :D

Regards
(e-mail address removed)
 
Back
Top