%socket() Function

The %socket() function 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 addr.family.

Syntax

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

Parameter(s)

addr.family

Specifies the addressing scheme used later to decode addresses. Valid values are defined in the include file: dm,bp,unix.h socket.h. Commonly used values are:

af$inet

IPv4

af$inet6

IPv6

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

Socket streams

sock$dgram

Datagram

protocol

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

Description

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

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

The socket is closed by a %close call or automatically when the FlashBASIC program terminates.

Example(s)

cfunction socket.builtin

include dm,bp,includes sysid.inc

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

%accept() Function

%bind() Function

%close() Function

%connect() Function

%gethostid() Function

%listen() Function

cfunction Statement

tape-socket Command