[client, info] = accept (s) ¶Accept incoming connection on specified socket.
Accepts an incoming connection on the socket s. The newly created socket is returned in client, and associated information in a struct info.
See the accept man pages for further details.
(s, portnumber) ¶Bind specific socket to port number.
See the bind man pages for further details.
(s, serverinfo) ¶Connect socket.
Connects the socket s following the information in the struct serverinfo which must contain the following fields:
addra string with the host name to connect to
portthe port number to connect to (an integer)
On successful connect, the returned status is zero.
See the connect man pages for further details.
(s) ¶Disconnect socket.
Disconnects the socket s. If successful, disconnect returns 0,
otherwise, it returns -1.
Since we can’t call fclose on the file descriptor directly, use this function to disconnect the socket.
ipaddres = gethostbyname (hostname) ¶Return IP address for host name.
For example:
gethostbyname ("localhost")
⇒ 127.0.0.1
See the gethostbyname man pages for details.
[data, status] = getsockopt (s, level, optname) ¶Get a socket option value from a socket.
Returns the value of level optname from the socket s.
Data type depends on the option used. status returns as 0 if no error.
See the getsockopt man pages for further details.
(s, backlog) ¶Listen on socket for connections.
Listens on socket s for connections. backlog specifies how large the queue of incoming connections is allowed to grow.
On success, zero is returned.
See the listen man pages for further details.
[data, count] = recv (s, len) ¶[data, count] = recv (s, len, flags) ¶Read data from specified socket.
Requests reading len bytes from the socket s.
The optional integer flags parameter can be used to modify the
behaviour of recv.
The read data is returned in the uint8 array data. The number of bytes read is returned in count.
You can get non-blocking operation by using the flag MSG_DONTWAIT
which makes the recv() call return immediately. If there is no
data, -1 is returned in count.
See the recv man pages for further details.
[data, count, src_info] = recvfrom (s, len) ¶[data, count, src_info] = recvfrom (s, len, flags) ¶Read data from specified socket.
Requests reading len bytes from the socket s.
The optional integer flags parameter can be used to modify the
behaviour of recvfrom.
The read data is returned in the uint8 array data. The number of bytes read is returned in count and a structure with fields addr and port contain the source of the data.
You can get non-blocking operation by using the flag MSG_DONTWAIT
which makes the recvfrom() call return immediately. If there is no
data, -1 is returned in count.
See the recvfrom man pages for further details.
[status, rfdset, wfdset, efdset] = select (nfds, rfdset, wfdset, efdset, timeout) ¶Wait for socket activity on selected sockets.
The fdsets are vectors of fds to check, for example [1 2 3]. Empty vectors equate to null.
nfds tests file descriptions in the range of 0 - nfds-1.
Timeout is can be either an real value for number of seconds, a struct with a tm_sec and tm_usec fields, or empty set for null.
status returns as 0 if timeout, or number of waiting sockets if ok.
See the select man pages for further details.
retval = sendto (s, data, dest_info) ¶retval = sendto (s, data, flags, dest_info) ¶Send data on specified socket.
Sends data on socket s to destination. data should be an uint8 array or a string.
The dest_info struct dest_info must contain the following fields:
addra string with the host name to send to
portthe port number to send to (an integer)
See the sendto man pages for further details.
status = setsockopt (s, level, optname, optvalue) ¶Set a socket option value on a socket.
status returns as 0 if no error.
See the setsockopt man pages for further details.
(s, how) ¶Shutdown all or part of a connection of a socket.
On success, zero is returned.
See the shutdown man pages for further details.
sock = socket () ¶sock = socket (domain) ¶sock = socket (domain, type) ¶sock = socket (domain, type, protocol) ¶Creates a socket.
domain is an integer, where the value AF_INET can be used to create an IPv4 socket.
type is an integer describing the socket. When using IP, specifying SOCK_STREAM gives a TCP socket.
protocol is currently not used and should be 0 if specified.
If no input arguments are given, default values AF_INET and SOCK_STREAM are used.
See the local socket reference for more details.