CREATE.SERVER.SOCKET

CREATE.SERVER.SOCKET()

Top  Previous  Next

 

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

 

addris the address on which to listen for incoming connections.

 

portis the port number on which to listen for incoming connections.

 

flagsis a flag value formed from the additive values below. For compatibility with earlier releases, this may be omitted and defaults to a TCP stream connection. The token values are defined in the SYSCOM KEYS.H include record.

Socket type, one of:

SKT$STREAMA stream connection (default)
SKT$DGRMA datagram type connection
SKT$USTREAMA named Unix domain socket connection

Protocol, one of:

SKT$TCPTransmission Control Protocol (default)
SKT$UDPUser Datagram Protocol

 

 

 

The addr argument may be

An IPV4 network IP address. Only incoming connections from other IPV4 addresses will be accepted.

An IPV6 network IP address Only incoming connections from other IPV6 addresses will be accepted.

A server name that will be translated to a network address

A null string. Connections may be made from either IPV4 or IPV6 addresses.

For Unix domain sockets, the addr argument is the pathname of the socket connection and the port argument is ignored.

 

When the IPADDR configuration parameter is used to cause QM to listen for incoming telnet, QMClient, QMNet or replication connections on a specific IP address, the SYSTEM(1071) function may be useful as the addr argument so that the same IP address is used by CREATE.SERVER.SOCKET.

 

Use of IPV6 must be enabled using the IPV6 configuration parameter.

 

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()