contents   index   previous   next

syntax:[timeout ,] socket1[, socket2



timeout - Maximum time to poll, in milliseconds, -1 for no timeout


socketN - A list of sockets to poll for data, or an array of sockets



object - The first supplied socket object which is ready for reading, or null if none is ready before the timeout is reached.



This method is an alternative to Socket ready(). The other ready method is a property of Socket instances, and only polls the current socket for data. This global method allows for polling of multiple sources, which is needed when multiple sockets are open. When any of the specified sockets are ready to be read from, then this method returns the first socket which is so ready. Note that these sockets can be either connected sockets or listening sockets. A listening socket that is ready to be read from means that a request is waiting. If no timeout is specified, then -1 (infinite) timeout is used.



#link <sesock>, Socket ready()



var listenSocket1 = Socket( 1000 );

var listenSocket2 = Socket( 1001 );


// Assume 'done' is a global flag somewhere

if( listenSocket1 != null && listenSocket2 != null )


   while( !done )


      var acceptSocket;

      if((acceptSocket =,

          [listenSocket1, listenSocket2])) != null)


         // Connect with socket ...



      // Do other stuff ...




/* This code opens two sockets for listening,

 * and then continuously polls

 * these two sockets for incoming connections.

 * Note that in a real

 * program, it would be better to create

 * a dynamic array which holds all

 * of the open sockets.