; TCPTimeouts Example ; ------------------- ; TCPTimeouts controls two waiting times: ; read_millis - how long a read may wait for data before ; erroring (default 10000 ms) ; accept_millis - how long AcceptTCPStream waits for a new ; connection (default 0 = return immediately) port=4006 server=CreateTCPServer(port) If server=0 Then Print "Could not listen on port "+port+" (it may be in use)" Else ; With the default accept timeout, Accept returns at once TCPTimeouts 10000,0 start=MilliSecs() stream=AcceptTCPStream(server) Print "TCPTimeouts 10000,0 : AcceptTCPStream returned "+stream+" after "+(MilliSecs()-start)+" ms" ; With a 2 second accept timeout, Accept WAITS for a caller ; (nobody connects here, so it gives up after ~2000 ms) TCPTimeouts 10000,2000 Print "" Print "Now waiting up to 2 seconds for a connection..." start=MilliSecs() stream=AcceptTCPStream(server) Print "TCPTimeouts 10000,2000 : AcceptTCPStream returned "+stream+" after "+(MilliSecs()-start)+" ms" ; Restore the defaults for any code that follows TCPTimeouts 10000,0 CloseTCPServer server EndIf Print "" Print "Press any key to close the example" WaitKey End