#GLSock Documentation
##GLSock
GLSock(type)
Description:
Creates a new socket.
Types:
<code>GLSOCK_TYPE_ACCEPTOR</code>
<code>GLSOCK_TYPE_TCP</code>
<code>GLSOCK_TYPE_UDP</code>
Returns:
*Userdata*
GLSock.Bind(host, port, callback(handle, errno))
Description:
Bindes the socket to the specific host and port
The host has to be a ip, it will not resolve.
Returns:
*boolean*
GLSock.Listen(backlog, callback(handle, errno))
Description:
Sets the socket into listen mode.
Always fails on GLSOCK_TYPE_TCP and GLSOCK_TYPE_UDP
Returns
*boolean*
GLSock.Accept(callback(handle, clienthandle, errno))
Description:
Begins an asynchronous accept operation. Whenever a client is accepted
it calls the callback. To keep the operation alive, call Accept on the
callback.
Always fails on GLSOCK_TYPE_TCP and GLSOCK_TYPE_UDP
Returns:
*boolean*
GLSock.Connect(host, port, callback(handle, errno))
Description:
Starts a connection to the host. Host will be resolved when its a hostname
When the connection was established, errno will be GLSOCK_ERROR_SUCCESS
Always fails on GLSOCK_TYPE_ACCEPTOR and GLSOCK_TYPE_UDP
Returns:
*boolean*
GLSock.Send(buffer, callback(handle, bytes_sent, errno))
Description:
Sends the data contained in buffer object to the endpoint. The buffer has to
be a GLSockBuffer object.
The outstanding data is not sent all at once, the callback can occour multiple
times.
Always fails on GLSOCK_TYPE_ACCEPTOR and GLSOCK_TYPE_UDP
Returns
*boolean*
GLSock.SendTo(buffer, host, port, callback(handle, bytes_sent, errno))
Description:
Same as GLSock.Send, hostname will be resolved.
Always fails on GLSOCK_TYPE_ACCETPR and GLSOCK_TYPE_TCP
Returns
*boolean*
GLSock.Read(bytes_to_read, callback(handle, buffer, errno))
Description:
Reads bytes_to_read bytes and calls the callback.
Always fails on GLSOCK_TYPE_ACCEPTOR and GLSOCK_TYPE_UDP
Returns:
*boolean*
GLSock.ReadUntil(delimiter, callback(handle, buffer, errno))
Description:
Reads until the internal buffer holds delimiter and calls the callback.
Always fails on GLSOCK_TYPE_ACCEPTOR and GLSOCK_TYPE_UDP
Returns:
**boolean* *
GLSock.ReadFrom(bytes_to_read, callback(handle, sender_host, sender_port, buffer, errno))
Description:
Will start an asynchronous operation for reading. The callback occours as soon data
is available.
Always fails on GLSOCK_TYPE_ACCETPR and GLSOCK_TYPE_TCP
Returns:
*boolean*
GLSock.Resolve(...)
Description:
The function is not available at the moment.
Returns:
false
GLSock.Cancel()
Description:
Cancels all pending asynchronous operations. The callbacks will receive the error
GLSOCK_ERROR_OPERATIONABORTED
Returns:
boolean
GLSock.Close()
Description:
Closes the socket. After this you will need to create a new instance to use it.
Also you should call Cancel before calling Close to avoid "possible" crashes.
Returns:
boolean
GLSock.Destroy()
Description:
Closes the socket and destroys it on the next polling. The handle will be no longer valid.
Returns:
* nil*
GLSock.Type()
Description:
Returns the type of the socket, can be one of the GLSOCK_TYPE_* values
Returns:
GLSOCK_TYPE_*
GLSock.RemoteAddress()
Description:
Returns the IPv4 address of the remote endpoint when available.
Returns:
string
GLSock.RemotePort()
Description:
Returns the port of the remote endpoint when available.
Returns:
*number *
##GLSockBuffer
GLSockBuffer()
Description:
Creates a new buffer object.
Returns:
GLSockBuffer object
GLSockBuffer.Write(data)
Description:
Writes data into current buffer position. Results the bytes written.
Returns:
count
GLSockBuffer.Read(count)
Description:
Read until the count has been reached, if theres not enough data
it will eventually return less.
Returns:
count, string
GLSockBuffer.WriteString(string)
Description:
Writes the string with null onto the buffer.
Returns:
count
GLSockBuffer.ReadString()
Description:
Reads a null terminated string, there has to be the null or it will fail.
Returns:
count, string
GLSockBuffer.WriteDouble(double [, swap_endian])
Description:
Writes a double onto the buffer.
Returns:
count
GLSockBuffer.ReadDouble([swap_endian])
Description:
Read a double from the buffer. Optionally swaps the endianness
Returns:
count, number
GLSockBuffer.WriteFloat(float [, swap_endian])
Description:
Writes a double onto the buffer. Optionally swaps the endianness
Returns:
count
GLSockBuffer.ReadFloat([swap_endian])
Description:
Reads a float from the buffer. Optionally swaps the endianness
Returns:
count, number
GLSockBuffer.WriteLong(long [, swap_endian])
Description:
Writes a unsigned long onto the buffer. Optionally swaps the endianness
Returns:
count
GLSockBuffer.ReadLong([swap_endian])
Description:
Reads a unsigned long from the buffer. Optionally swaps the endianness
Returns:
count, number
GLSockBuffer.WriteShort(short [, swap_endian])
Description:
Writes a unsigned short onto the buffer. Optionally swaps the endianness
Returns:
count
GLSockBuffer.ReadShort([swap_endian])
Description:
Reads a unsigned short from the buffer. Optionally swaps the endianness
Returns:
count, number
GLSockBuffer.WriteByte(byte)
Description:
Writes a unsigned char onto the buffer.
Returns:
count
GLSockBuffer.ReadByte()
Description:
Reads a unsigned char from the buffer.
Returns:
count, number
GLSockBuffer.Size()
Description:
Returns the current size of the buffer.
Returns:
number
GLSockBuffer.Tell()
Descriptions:
Returns the current position of the buffer.
Returns:
number
GLSockBuffer.Seek(pos, method)
Descriptions:
Works like fseek, will set the current buffer positon where
to write/read.
Methods:
GLSOCKBUFFER_SEEK_SET
GLSOCKBUFFER_SEEK_CUR
GLSOCKBUFFER_SEEK_END
Returns:
boolean
GLSockBuffer.EOB()
Description:
Returns if the buffer is at the end. (Position == Size)
Returns:
boolean
GLSockBuffer.Empty()
Description:
Returns if the buffer is currently empty.
Returns:
boolean
GLSockBuffer.Clear(count [, position = 0])
Description:
Erases the content from position until to count.
Returns:
boolean
##Error Codes GLSOCK_ERROR_SUCCESS GLSOCK_ERROR_ACCESSDENIED GLSOCK_ERROR_ADDRESSFAMILYNOTSUPPORTED GLSOCK_ERROR_ADDRESSINUSE GLSOCK_ERROR_ALREADYCONNECTED GLSOCK_ERROR_ALREADYSTARTED GLSOCK_ERROR_BROKENPIPE GLSOCK_ERROR_CONNECTIONABORTED GLSOCK_ERROR_CONNECTIONREFUSED GLSOCK_ERROR_CONNECTIONRESET GLSOCK_ERROR_BADDESCRIPTOR GLSOCK_ERROR_BADADDRESS GLSOCK_ERROR_HOSTUNREACHABLE GLSOCK_ERROR_INPROGRESS GLSOCK_ERROR_INTERRUPTED GLSOCK_ERROR_INVALIDARGUMENT GLSOCK_ERROR_MESSAGESIZE GLSOCK_ERROR_NAMETOOLONG GLSOCK_ERROR_NETWORKDOWN GLSOCK_ERROR_NETWORKRESET GLSOCK_ERROR_NETWORKUNREACHABLE GLSOCK_ERROR_NODESCRIPTORS GLSOCK_ERROR_NOBUFFERSPACE GLSOCK_ERROR_NOMEMORY GLSOCK_ERROR_NOPERMISSION GLSOCK_ERROR_NOPROTOCOLOPTION GLSOCK_ERROR_NOTCONNECTED GLSOCK_ERROR_NOTSOCKET GLSOCK_ERROR_OPERATIONABORTED GLSOCK_ERROR_OPERATIONNOTSUPPORTED GLSOCK_ERROR_SHUTDOWN GLSOCK_ERROR_TIMEDOUT GLSOCK_ERROR_TRYAGAIN GLSOCK_ERROR_WOULDBLOCK