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)
where
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.
Example
SRVR.SKT = CREATE.SERVER.SOCKET("", 0) 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: ACCEPT.SOCKET.CONNECTION, CLOSE.SOCKET, OPEN.SOCKET(), READ.SOCKET(), SERVER.ADDR(), SET.SOCKET.MODE(), SOCKET.INFO(), WRITE.SOCKET() |