WRITE.SOCKET()

WRITE.SOCKET()

Top  Previous  Next

 

The WRITE.SOCKET() function writes data to a socket.

 

 

Format

 

WRITE.SOCKET(skt, data, flags, timeout)

 

where

 

sktis the socket variable returned by ACCEPT.SOCKET.CONNECTION() (stream connection), CREATE.SERVER.SOCKET() (datagram connection) or OPEN.SOCKET().

 

datais the data to be written.

 

flagsis a value determining the mode of operation of the socket for this write, formed by adding the values of tokens defined in the SYSCOM KEYS.H record. The flags available in this release are:
SKT$BLOCKINGSets the mode of data transfer as blocking.
SKT$NON.BLOCKINGSets the mode of data transfer as non-blocking.

If neither blocking flag is given, the blocking mode set when the socket was opened is used.

 

timeoutis the timeout period in milliseconds. A value of zero implies no timeout.

 

 

The WRITE.SOCKET() function writes the given data and returns the number of bytes written. If non-blocking mode is used or a timeout occurs, this byte count may be less than the length of the data. The remaining data can be written with a subsequent call to WRITE.SOCKET() when buffer space becomes available.

 

The STATUS() function returns zero if the action is successful, or a non-zero error code if an error occurs. A timeout will return an error code of ER$TIMEOUT as defined in the SYSCOM ERR.H record.

 

 

Example

 

SKT = OPEN.SOCKET("193.118.13.14", 3000, SKT$BLOCKING)

IF STATUS() THEN STOP 'Cannot open socket'

N = WRITE.SOCKET(SKT, DATA, 0, 0)

CLOSE.SOCKET SKT

 

This program fragment opens a connection to port 3000 of IP address 193.118.13.14, sends the data in DATA and then closes the socket.

 

 

See also:

Using Socket Connections, ACCEPT.SOCKET.CONNECTION, CLOSE.SOCKET, CREATE.SERVER.SOCKET(), OPEN.SOCKET(), READ.SOCKET(), SELECT.SOCKET(), SERVER.ADDR(), SET.SOCKET.MODE(), SOCKET.INFO()