Home  Contents

rawio.socket

Rawio Core4 Lua Event System

SYNOPSIS

handle = rawio.socket(type)

DESCRIPTION

Creates a file handle instance for network communication. The type must be either "tcp" to create a TCP stream socket, or "udp" to create a UDP packet socket.

TCP sockets are full-duplex byte streams. A stream socket must be in a connected state before any data can be sent or received on it. Connections to other sockets are initiated by calling rawio:connect(). A socket can be set up to accept incoming connections using the functions rawio:bind(), rawio:listen() and rawio:accept(). The TCP protocol makes sure that transmission errors are corrected. Data written to a TCP socket either makes it to the other end or you will see an error (Eventually. The TCP standard has quite large timeouts.)

A UDP socket uses blocks of data and works connectionless. UDP has no build in error recovery. It is up to the application to detect lost transmissions and retry. UDP over Ethernet has a CRC checksum protection however, so if transmitted data makes it to the other end, it's correct. Use rawio:bind() to set up the local port number and IP address the UDP socket shall be reachable by peers. Functions for transmitting and receiving over UDP are rawio:sendto() and rawio:recvfrom(). To make exchanging data with a fixed peer easier, call rawio:connect() on an UDP socket. You can then use the standard rawio:write() and rawio:read() commands on that socket.

RETURN VALUE

On success, a rawio handle is returned. On error, three values are returned: nil, a string describing the error (The result of the C library call strerror() on the errno code) and the errno number from the standard C library.

SEE ALSO