Navigation:  Programming Cookbook > Sockets Connectivity >

Using the Non-Blocking Calls

Previous pageReturn to chapter overviewNext page

As mentioned previously, there are a number of non-blocking versions of some of the Socket calls available for use in simple situations where the additional complexity of starting a background process or using a BlockingCallMonitor is not warranted. The following non-blocking calls are available:


Similar to #accept, this method starts listening for a client connection but returns immediately. When when a connection is accepted, a #connectionAccepted: event is triggered off the ServerSocket with the newly connected server-side Socket as its parameter.


Similar to #connect for client Sockets, this method attempts to connect to an appropriate server but returns immediately. When the connection request is accepted by the server, a #connected event is triggered off the Socket.


The #receive, #receiveByte and #receiveByteArray: methods all block until sufficient data is read so that they can complete. However, it is possible to detect whether a Socket has input present at any time by using the #hasInput method. This returns immediately and answers true if data is available or false otherwise.

A Socket will also trigger a #dataRead event off itself whenever new data is received across the connection. Intercepting this can be used to indicate whether is then appropriate to actually receive the new data using one of the blocking calls above.