On Sat, Jan 2, 2010 at 9:31 AM, Matthew Brand <[email protected]> wrote: > int bytes = 0; > // do { > try { > bytes = JSocket.Receive(buffer, > buffer.Length, 0); > reply = reply + > System.Text.Encoding.ASCII.GetString(buffer, 0, bytes); > // Print("reply was:" + reply); > } > catch (System.Net.Sockets.SocketException ex) { > Print("Socket exception on read:" + > ex.SocketErrorCode); > } > > // } while (bytes > 0); Loop causes a hang. Do not know why!
I did not look to see if you had this socket configured for blocking or non-blocking reads, but either way this loop should never exit. Here's a quote from the relevant documentation: If no data is available for reading, the Receive method will block until data is available, unless a time-out value was set by using Socket.ReceiveTimeout. If the time-out value was exceeded, the Receive call throws a SocketException. 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. Normally, the .Receive() method would never exit. But if you are non-blocking, your "bytes" variable will not be updated. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
