-
WSAStartup ()
Load the WS2_32.DLL winsock library version 2.2.
Description:
Must be called successfully before using any Winsock functions.
Return:
Returns zero if successful, otherwise returns a non-zero error code.
-
WSACleanup ()
Free socket resources and unload the Winsock library.
Return:
Returns zero if successful, otherwise returns SOCKET_ERROR.
-
WSAGetLastError ()
Returns the error status for the last operation that failed.
Return:
integer: error code
-
htonl (atom)
Perform host to network type conversion on a long (4-byte) integer.
Params:
-
htons (atom)
Perform host to network type conversion on a short (2-byte) integer.
Params:
-
socket (integer, integer, integer)
Creates a new socket of the specified family and type.
Params:
-
integer af
Address family, typically AF_INET for internet addresses.
-
integer socktype
Socket type, use SOCK_DGRAM for UDP or SOCK_STREAM for TCP.
-
integer pf
Protocol family, set to zero and let Windows determine it
based on the address family.
Return:
If successful, returns a pointer referencing the new socket.
Otherwise, INVALID_SOCKET is returned.
-
setsockopt (integer, integer, object)
Sets the current value for a socket option.
Params:
-
integer Socket
-
integer Option
-
object OptVal
Description:
Sets the current value for a socket option associated with a socket of any
type, in any state. Only top-level socket options (SOL_SOCKET) are supported
here, to make things simple.
Return:
Returns zero or SOCKET_ERROR on failure.
-
gethostbyname (sequence)
Retrieves host information corresponding to a host name from a host database.
Params:
Description:
This function returns only the address portion of Winsock hostent structure.
-
sockaddr_in (integer, sequence, integer)
Populate a sockaddr_in structure with an internet address and port number.
Params:
-
integer Family
-
sequence Host
-
integer Port
Description:
This function calls gethostbyname() to convert a domain name or
dotted decimal string into a machine readable address.
It also takes care of all host-to-network type conversions.
To fill the structure with the IP address of the local host,
pass an empty sequence as the host parameter. To have the system
automatically select an unused port on the local host, pass 0
as the port parameter.
Return:
A sequence representing the socket address (struct sockaddr_in)
or SOCKET_ERROR on failure.
Example:
sockAddrIn("www.rapideuphoria.com", 80)
sockAddrIn("127.0.0.1", 8080) -- Port 8080 on the localhost
sockAddrIn("", 0) -- Any port on the localhost
-
bind (integer, sequence)
Associates a local address with a socket.
Params:
-
integer sockfd
-
sequence sockaddr
Description:
Must be used on an unconnected socket before a subsequent call to the
listen() function.
Return:
Returns zero or SOCKET_ERROR on failure.
-
connect (integer, sequence)
Establishes a connection to a specified socket.
Params:
-
integer sockdesc
-
sequence sockaddr
Return:
Returns zero if successful, otherwise returns SOCKET_ERROR.
-
listen (integer, integer)
Places a bound socket in a state in which it is listening for an incoming connection.
Params:
Return:
Returns zero if successful, otherwise returns SOCKET_ERROR.
-
accept (integer)
Permits an incoming connection attempt on a socket.
Params:
Return:
Returns a value that is a descriptor for a new socket. The returned value
is a handle for the socket on which the actual connection is made. In case
of error, this function returns a value of INVALID_SOCKET.
-
select (sequence, sequence, sequence, sequence)
Determine the status of one or more sockets.
Params:
-
sequence ReadSet
Sockets to check for read status
-
sequence WriteSet
Sockets to check for write status
-
sequence ErrorSet
Sockets to check for error status
-
sequence Timeout
Timeout is a sequence of the form {seconds, microsecs} that specifies the
maximum time select() should wait before returning. If the timeout value is
{0,0} then select() will check the status of sockets and return immediately.
If Timeout is an empty sequence, select() will block indefinitely until at
least one of the sockets meets the specified criteria.
Description:
For each socket, the caller can request information on read, write, or
error status. The set of sockets for which a given status is requested is
indicated by a sequence of socket handles.
Return:
{integer result, sequence readSet, sequence writeSet, sequence errorSet}
Status = SOCKET_ERROR : An error occurred.
Status = 0 : The time limit expired.
Status > 0 : The total number of sockets that meet the criteria;
sequences contain handles of the matching sockets.
Example:
Wait for 10 seconds or until Sock1 or Sock2 have data to read:
select({Sock1,Sock2}, {}, {}, {10,0})
Check for errors on Sock1 and return immediately:
select({}, {}, {Sock1}, {0,0})
Wait indefinitely for incoming Sock1 data, or Sock2 is ready to send:
select({Sock1},{Sock2},{},{})
-
GetSockName (integer)
Retrieves the local name (family, address, and port) for a socket.
Params:
Description:
This is the only way to determine the local association of socket/name
when a connect() call has been made without doing a bind() first.
Return:
A sequence representing the socket address (struct sockaddr_in)
or SOCKET_ERROR on failure.
-
GetPeerName (integer)
Retrieves the name of the peer to which a socket is connected.
Params:
Description:
This does not work for unconnected datagram sockets.
Return:
A sequence representing the peer address (struct sockaddr_in)
or SOCKET_ERROR on failure.
-
GetPort (atom)
get the port that is bound to the socket
Params:
Description:
low-level command
Return:
integer: port number
Example:
port_used = GetPort(tcpSocket)
port_used = GetPort(activeConnections[cnx][TCP_SOCKET])
-
send (integer, sequence)
Sends data on a connected socket.
Params:
-
integer socket
-
sequence message
Return:
Returns the actual number of bytes transmitted, which may be less than the
total message length. Returns SOCKET_ERROR on failure.
-
sendto (integer, sequence, integer, sequence)
Sends data on an unconnected socket to a specific destination.
Params:
-
integer Socket
-
sequence Message
-
integer Flags
-
sequence InetSockAddr
Return:
Returns the actual number of bytes transmitted, or SOCKET_ERROR on failure.
-
recv (integer, integer)
Receives data from a connected or bound socket.
Params:
-
integer socket
-
integer bytes
Return:
Returns a sequence of the form {result, buffer} where
result = the actual number of bytes received or SOCKET_ERROR, and
buffer = a sequence containing the received characters.
-
closesocket (integer)
Closes an existing socket.
Params:
Return:
Returns zero if successful, otherwise returns SOCKET_ERROR.