SGScript Sockets library

Table of Contents


Description

The main focus of support in this library was to support Internet sockets in a cross-platform way. Every other possible use of sockets currently is not supported.

The library is compiled to a 'sgssockets' shared library so it can be included this way (assuming that, on Linux and similar systems, LD_LIBRARY_PATH is set correctly):

include "sgssockets";

SGScript API

Objects:

Functions:

Constants:


socket_error [function]

socket_error( bool as_text = false )

returns the last error received from working with the sockets, possibly as text


socket_geterrnobyname [function]

socket_geterrnobyname( string name )

returns a socket error code as integer by its name (for example, "EWOULDBLOCK")


socket_address [object]


socket_address [function]

socket_address( int addrfamily, string addrstring[, int port ])

create address from string, optionally set port


socket_address_frombytes [function]

socket_address_frombytes( int addrfamily, string addrbytes[, int port ])

create address from byte buffer, optionally set port


socket_getaddrinfo [function]

socket_getaddrinfo( string addrstring, string port[, int hint_socktype[, int hint_addrfamily ]])

resolve domain name to address, optionally specifying socket type and address family needed


socket_gethostname [function]

socket_gethostname()

return the host name of computer


socket [object]


socket.bind [method]

socket.bind( int port )

bind the socket to a port for listening


socket.listen [method]

socket.listen( int queuesize )

wait for connection requests, return if successful


socket.accept [method]

socket.accept()

retrieve the socket and address from the incoming connection


socket.connect [method]

socket.connect( socket_address )

attempt to create a connection to a specific address, return if successful


socket.send [method]

socket.send( string buffer[, int flags ])

attempt to send data over a connected socket, return amount of data sent or false on failure


socket.sendto [method]

socket.sendto( string buffer, socket_address[, int flags ])

attempt to send data over an unconnected socket to the specified address, return amount of data sent or false on failure


socket.recv [method]

socket.recv( int maxlength[, int flags ])

attempt to receive at most maxlength bytes of pending data


socket.recvfrom [method]

socket.recvfrom( int maxlength[, int flags ])

attempt to receive at most maxlength bytes of pending data, return address of sender with data


socket.shutdown [method]

socket.shutdown( int type )

shut down the socket, disabling the specified kind of operations


socket.close [method]

socket.close()

close the socket, disabling further operations


socket.getpeername [method]

socket.getpeername()

return the host name of the device on the other end of the socket, if it's connected


socket [function]

socket( int addrfamily, int socktype, int protocol )

create a socket with the specified parameters


socket_tcp [function]

socket_tcp([ bool ipv6 ])

create a TCP socket


socket_udp [function]

socket_udp([ bool ipv6 ])

create a UDP socket


socket_select [function]

socket_select( array readscl, array writescl, array errorscl[, real timeout ])

check socket lists for state, optionally specifying maximum wait time

- -1 on error - >0 if sockets have acquired the necessary states (the total number of such sockets is returned) - 0 if time limit was reached


AF_/PF_ [constants]

address family / protocol family constants

All of these constants are available with both AF_ and PF_ prefixes.


SOCK_ [constants]

socket type constants


IPPROTO_ [constants]

internet protocol type constants


MSG_ [constants]

message flag constants


SHUT_ [constants]

shutdown type constants (non-Windows version), same as SD_ constants


SD_ [constants]

shutdown type constants (Windows version), same as SHUT_ constants


All SGScript functions (A-Z)


All SGScript constants (A-Z)


C API


socket [type]

socket

a socket object contains the socket identifier directly in the data pointer


socket_address [type]

socket_address

a socket address object contains the address of any type (family), data pointer points to a sockaddr_storage struct