Tip: Avoid using the EOF procedure as a way to check to see if a socket is empty. Instead, structure your communication across the socket so that using EOF is not necessary to know when the communication is complete.
Most UNIX systems maintain a daytime server on the daytime port (port 13). These servers send a 1 line response when connected to, containing the current time of day.
; To obtain the current time from the host bullwinkle:
SOCKET, 1, 'bullwinkle','daytime'
READF, 1, date
Wed Sep 15 17:20:27 1999
SOCKET, Unit, Host, Port [, /ACCEPT] [, CONNECT_TIMEOUT=value] [, ERROR=variable] [, /GET_LUN] [, /LISTEN] [, PORT=variable] [, /RAWIO] [, READ_TIMEOUT=value] [, /SWAP_ENDIAN] [, /SWAP_IF_BIG_ENDIAN] [, /SWAP_IF_LITTLE_ENDIAN] [, WIDTH=value] [, WRITE_TIMEOUT=value]
UNIX-Only Keywords: [, /STDIO]
The unit number to associate with the opened socket.
The name of the host to which the socket is connected. This can be either a standard Internet host name (e.g.info.cern.ch) or a dot-separated numeric address (e.g. 22.214.171.124).
The port to which the socket is connected on the remote machine. If this is a well-known port (as contained in the /etc/services file on a UNIX host), then you can specify its name (e.g. daytime); otherwise, specify a number.
Set this keyword to only accept communications on a specified LUN.
Set this keyword to the number of seconds to wait before giving up and issuing an error to shorten the connect timeout from the system-supplied default. Most experts recommend that you not specify an explicit timeout, and instead use your operating system defaults.
Note: Although you can use CONNECT_TIMEOUT to shorten the timeout, you cannot increase it past the system-supplied default.
A named variable in which to place the error status. If an error occurs in the attempt to open the socket, IDL normally takes the error handling action defined by the ON_ERROR and/or ON_IOERROR procedures. SOCKET always returns to the caller without generating an error message when ERROR is present. A nonzero error status indicates that an error occurred. The error message can then be found in the system variable !ERROR_STATE.MSG.
OPENR, Unit, 'data.dat'
you can use the single statement:
OPENR, Unit, 'data.dat', /GET LUN
Set this keyword to tell this socket to listen on the specified port.
A named variable which contains the port of the current socket.
Set this keyword to disable all use of the standard operating system I/O for the file, in favor of direct calls to the operating system. This allows direct access to devices, such as tape drives, that are difficult or impossible to use effectively through the standard I/O. Using this keyword has the following implications:
- No formatted or associated (ASSOC) I/O is allowed on the file. Only READU and WRITEU are allowed.
- Normally, attempting to read more data than is available from a file causes the unfilled space to be set to zero and an error to be issued. This does not happen with files opened with RAWIO. When using RAWIO, the programmer must check the transfer count, either via the TRANSFER_COUNT keywords to READU and WRITEU, or the FSTAT function.
- The EOF and POINT_LUN functions cannot be used with a file opened with RAWIO.
- Each call to READU or WRITEU maps directly to UNIX read(2) and write(2) system calls. The programmer must read the UNIX system documentation for these calls and documentation on the target device to determine if there are any special rules for I/O to that device. For example, the size of data that can be transferred to many cartridge tape drives is often forced to be a multiple of 512 bytes.
Set this keyword to the number of seconds to wait for data to arrive before giving up and issuing an error. By default, IDL blocks indefinitely until the data arrives. Typically, this option is unnecessary on a local network, but it is useful with networks that are slow or unreliable.
This keyword is only available on UNIX platforms.
Under UNIX, forces the file to be opened via the standard C I/O library (stdio) rather than any other more native OS API that might usually be used. This is primarily of interest to those who intend to access the file from external code, and is not necessary for most uses.
Note: Under Windows, the STDIO feature is not possible. Requesting it causes IDL to throw an error.
Set this keyword to swap byte ordering for multi-byte data when performing binary I/O on the specified file. This is useful when accessing files also used by another system with byte ordering different than that of the current host.
Setting this keyword is equivalent to setting SWAP_ENDIAN; it only takes effect if the current system has big endian byte ordering. This keyword does not refer to the byte ordering of the input data, but to the computer hardware.
Setting this keyword is equivalent to setting SWAP_ENDIAN; it only takes effect if the current system has little endian byte ordering. This keyword does not refer to the byte ordering of the input data, but to the computer hardware.
The desired output width. When using the defaults for formatted output, IDL uses the following rules to determine where to break lines:
- If the output file is a terminal, the terminal width is used.
- Otherwise, a default of 80 columns is used.
The WIDTH keyword allows the user to override this default.
Set this keyword to the number of seconds to wait to send data before giving up and issuing an error. By default, IDL blocks indefinitely until it is possible to send the data. Typically, this option is unnecessary on a local network, but it is useful with networks that are slow or unreliable.
Added SWAP_IF_BIG_ENDIAN and SWAP_IF_LITTLE_ENDIAN keywords
|8.5||Added ACCEPT, LISTEN, and PORT keywords.|