basic.%socket C Function/BASIC Program

basic.%socket

Command basic.%socket C Function/BASIC Program
Applicable release versions: AP/Unix
Category BASIC Program (486)
Description creates a socket in the specified 'addr.family' and of the specified 'type'. A protocol can be specified or assigned by the system. If the protocol is left unspecified (with a value of 0), the system selects an appropriate protocol in the specified address family.

To compile successfully, the statement 'cfunction socket.builtin' must be included in the source code.

'addr.family' Specifies the addressing scheme which will be used later to decode addresses. Valid values are defined in the include "dm,bp,unix.h socket.h". Commonly used values are:

AF$UNIX Unix path names.
AF$INET ARPA Internet.

'type' Specifies the semantics of communication. Valid values are defined in the include "dm,bp,unix.h socket.h". Commonly used values are:

SOCK$STREAM Unix streams.
SOCK$DGRAM Datagram

'protocol' Should be left to 0, to let the system assign the protocol.

Upon successful completion, a valid file descriptor is returned. If the call fails, a value of -1 is returned and the function 'SYSTEM(0)' returns the value of 'errno'.

The socket is closed by a %close call or automatically when the basic program terminates
Syntax n=%socket( addr.family, type, protocol )
Options
Example
cfunction socket.builtin
include dm,bp,unix.h socket.h

fd=%socket( AF$INET, SOCK$STREAM, 0 )
if fd<0 then
  crt 'Socket creation failed. Error ':system(0)
Purpose
Related basic.cfunction
basic.%close
basic.%bind
basic.%accept
basic.%listen
basic.%gethostid
basic.%connect
tcl.tape-socket