Socket ready()
syntax: |
socket.ready([timeout]) |
where: |
timeout - Maximum time to poll, in milliseconds, or -1 for no timeout
|
return: |
boolean - whether the socket is ready for reading in the specified time.
|
description: |
This method is very similar to Socket.select(), except that it only polls the current socket for input. If no timeout is specified or it is -1, then the socket is polled indefinitely, unless there is an error. This method is useful for simple applications, when there are just a few sockets open, or in special instances where the Socket.select() method is impractical or impossible.
|
see: |
#link <sesock>, Socket select()
|
example: |
var listenSocket = Socket( 1000 );
// Assume 'done' is a global flag if( listenSocket != null ) { while( !done ) { if( listenSocket.ready(10) ) { // Open connection with accept() ... }
// Do other idle stuff... }
listenSocket.close(); }
/* This code creates a socket listening * on port 1000, and continuously * polls it to see if there is * an incoming connection, alternatively doing * idle code when there is no connection ready. */ |