CREATE.SERVER.SOCKET() |
|
|
The CREATE.SERVER.SOCKET() function creates a server socket on which a program may wait for incoming connections.
Format
CREATE.SERVER.SOCKET(addr, port, flags)
where
Socket type, one of:
Protocol, one of:
If the action is successful, this function returns the socket variable associated with the new server port and the STATUS() function returns zero.
If unsuccessful, the STATUS() function returns an error code that can be used to determine the cause of failure.
Use of CREATE.SERVER.SOCKET() within a phantom process makes that process consume a licence.
Example
SRVR.SKT = CREATE.SERVER.SOCKET("", 4000, SKT$STREAM + SKT$TCP) IF STATUS() THEN STOP 'Cannot initialise server socket' SKT = ACCEPT.SOCKET.CONNECTION(SRVR.SKT, 0) IF STATUS() THEN STOP 'Error accepting connection' DATA = READ.SOCKET(SKT, 100, SKT$BLOCKING, 0) CLOSE.SOCKET SKT CLOSE.SOCKET SRVR.SKT
This program fragment creates a server socket, waits for an incoming connection, reads a single data packet from this connection and then closes the sockets.
See also: Using Socket Connections, ACCEPT.SOCKET.CONNECTION, CLOSE.SOCKET, OPEN.SOCKET(), READ.SOCKET(), SELECT.SOCKET(), SERVER.ADDR(), SET.SOCKET.MODE(), SOCKET.INFO(), WRITE.SOCKET() |