SocketPingSetup
(Engine-Level Function)
Description: | Starts the transmission of automatic keep-alive "ping" messages through a socket stream. |
Returns: | Nothing |
Usage: | Script Only. |
Function Groups: | Stream and Socket |
Related to: | BuffStream | ServerSocket | ClientSocket |
Format: | SocketPingSetup(SocketStream, PingStream, TimeInterval) |
Parameters: |
SocketStream |
Required. Any valid socket stream, typically obtained from a ClientSocket or ServerSocket. |
PingStream |
Required. A stream which contains the "ping" packet to be transmitted. |
TimeInterval |
Required. The interval, in seconds, between transmissions. |
Comments: | SocketPingSetup is used to enable the regular transmission of a small packet (a "ping") down a socket stream. The ping is only transmitted if there has been no other transmission for the specified time interval. Pinging continues automatically until the socket stream is closed. This function is useful for keeping a connection open which may be closed by the computer operating system due to inactivity. |
Examples:
Init [ If 1 Wait; [ Socket = ClientSocket(0, TargetMachine, Port, TransmitLen, ReceiveLen, 0); ] ] Wait [ If PickValid(ValueType(Socket == 8 {stream}, 0) Open; [ SocketPingSetup(Socket, BuffStream("ping"), 10); ] If PickValid(ValueType(Socket != 8{stream}), 0) Retry; ] Open [ . . . ]
This will open a socket stream and, when the stream is open, enable the automatic transmission of the text message "ping" after every 10 seconds of no other transmission being sent.