basic.%socket

C Function/BASIC Program, Releases: AP/Unix

Creates a socket.

Syntax

n=%socket( addr.family, type, protocol )

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

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)

See Also

Command Name Type Description
basic.cfunction Definition Declare a list of C functions.
basic.%close C Function Closes a Unix file.
basic.%bind C Function Binds a name to a socket.
basic.%accept C Function Accept a connection on a socket.
basic.%listen C Function Listens for incoming connections and limits the backlog of incoming connections.
basic.%gethostid C Function Gets the unique identifier of the current host.
basic.%connect C Function Establishes a connection with a host through sockets.
tcl.tape-socket Verb: Access Tape device across a network

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.