Murl Engine Lua Addon API  Version 1.0 beta
Murl.Net.ISocket

The socket interface.

Several methods are blocking calls when waiting for network response.

(!) Do not use this class directly in the logic code. Use Net::ISocketClient and Net::ISocketServer interfaces instead.


Table members

Typedefs


Murl.Net.ISocket.SharedPtr

Definition of the socket shared pointer.

Returns
Murl.SharedPointer.NetISocket

Murl.Net.ISocket.PtrArray

Definition of the socket shared pointer array.

Returns
Murl.Array.SharedPointerNetISocket


Functions



Methods


SetName(name)

Set the name of the socket.

SetName(String name)

Parameters
nameThe name of the socket.

GetName()

Get the name of the socket.

String GetName()

Returns
String The name of the socket.

SetUniqueIdentifier(uniqueId)

Set the unique identifier of the socket.

SetUniqueIdentifier(String uniqueId)

Parameters
uniqueIdThe unique identifier of the socket.

GetUniqueIdentifier()

Get the unique identifier of the socket.

String GetUniqueIdentifier()

Returns
String The unique identifier of the socket.

ConnectTcp(address)

Connects to a specified server address using tcp. Enables reuse-address, keep-alive and tcp-no-delay socket option.

Boolean ConnectTcp(Murl.SharedPointer.NetISocketAddress address)

Parameters
addressThe address of the server to connect.
Returns
Boolean true if successful.

ConnectTcpNonBlocking(address)

Connects to a specified server address using tcp with non blocking. Enables reuse-address, keep-alive, tcp-no-delay and non-blocking socket option.

Boolean ConnectTcpNonBlocking(Murl.SharedPointer.NetISocketAddress address)

Parameters
addressThe address of the server to connect.
Returns
Boolean true if successful.

ConfirmConnectTcpNonBlocking()

Confirm connect using tcp with non blocking. When connection by ConnectTcpNonBlocking() a write select to the socket indicates the connection and must be confirmed by calling this method.

Boolean ConfirmConnectTcpNonBlocking()

Returns
Boolean true if connection established, false if connection error.

ConnectUdp(address)

Connects to a specified server address using udp. Enables tcp-no-delay socket option.

Boolean ConnectUdp(Murl.SharedPointer.NetISocketAddress address)

Parameters
addressThe address of the server to connect.
Returns
Boolean true if successful.

BindTcpListen(address, maxQueue)

Bind a listener to accept tcp connections. Enables reuse-address and keep-alive socket option.

Boolean BindTcpListen(Murl.SharedPointer.NetISocketAddress address, Integer maxQueue)

Parameters
addressThe address to listen for incoming connections. The address specifies the port to listen and the ip-address to find the correct network adapter (any-address is listening on all adapters).
maxQueueThe maximum length of the queue of pending connections.
Returns
Boolean true if successful.

BindUdpListen(address)

Bind a listener to accept udp connections. Enables reuse-address socket option.

Boolean BindUdpListen(Murl.SharedPointer.NetISocketAddress address)

Parameters
addressThe address to listen for incoming connections. The address specifies the port to listen and the ip-address to find the correct network adapter (any-address is listening on all adapters).
Returns
Boolean true if successful.

CreateUdpBroadcast()

Create a socket to send udp broadcast. Enables reuse-address and broadcast socket option.

Boolean CreateUdpBroadcast()

Returns
Boolean true if successful.

Disconnect()

Disconnect the socket.

Boolean Disconnect()

Returns
Boolean true if successful.

IsConnected()

Check if the socket is connected.

Boolean IsConnected()

Returns
Boolean true if the socket is connected.

IsConnecting()

Check if the socket is connecting in non blocking mode.

Boolean IsConnecting()

Returns
Boolean true if the socket is connected in non blocking mode.

Accept(listenSocket)

Accept connection on the socket. Enables keep-alive and tcp-no-delay socket option after accept.

Boolean Accept(Murl.SharedPointer.NetISocket listenSocket)

Parameters
listenSocketThe socket which is listening for the connection.
Returns
Boolean true if successful.

AcceptNonBlocking(listenSocket)

Accept connection on the socket. Enables keep-alive, tcp-no-delay and non-blocking socket option after accept.

Boolean AcceptNonBlocking(Murl.SharedPointer.NetISocket listenSocket)

Parameters
listenSocketThe socket which is listening for the connection.
Returns
Boolean true if successful.

Pair(pairSocket)

Create a socket pair ready to communicate.

Boolean Pair(Murl.SharedPointer.NetISocket pairSocket)

Parameters
pairSocketThe socket to connect with this socket.
Returns
Boolean true if successful.

Select(readSockets, writeSockets, timeout)

Wait for ready to read and write sockets with timeout.

Integer, Murl.Array.SharedPointerNetISocket, Murl.Array.SharedPointerNetISocket Select(Murl.Array.SharedPointerNetISocket readSockets, Murl.Array.SharedPointerNetISocket writeSockets, Number timeout)

Parameters
readSocketsArray of read sockets to wait for.
writeSocketsArray of write sockets to wait for.
timeoutThe maximum time to wait in seconds, -1 for no timeout.
Returns
Integer The number of selected sockets, zero if the timeout was reached or -1 if select failed.
Murl.Array.SharedPointerNetISocket readSockets Array of read sockets to wait for.
Murl.Array.SharedPointerNetISocket writeSockets Array of write sockets to wait for.

IsReadSelected()

Check if the socket was read selected during the last Select(). The select status is valid until the next call of Select() or the socket is closed due to errors or Destroy() is called.

Boolean IsReadSelected()

Returns
Boolean true if the socket was read selected during the last Select().

IsWriteSelected()

Check if the socket was write selected during the last Select(). The select status is valid until the next call of Select() or the socket is closed due to errors or Destroy() is called.

Boolean IsWriteSelected()

Returns
Boolean true if the socket was write selected during the last Select().

Receive(data)

Receive data from the socket.

Boolean, Murl.Data Receive(Murl.Data data)

Parameters
dataThe data object to store the incoming data. The data object's byte size is the maximum number of bytes to receive. If the data object is empty a size of 1500 bytes is reserved internally.
Returns
Boolean true if successful. The data object is resized to the number of bytes received, otherwise if receive failed the data object is empty.
Murl.Data data The data object to store the incoming data. The data object's byte size is the maximum number of bytes to receive. If the data object is empty a size of 1500 bytes is reserved internally.

Send(data)

Send the entire data to the socket.

Boolean Send(Murl.ConstData data)

Parameters
dataThe data to send.
Returns
Boolean true if successful.

Send(data, byteOffset)

Send data form a specified offset to the socket. In non-blocking operation this method sends only a portion of data and has to be called in a loop which allows to monitor the data transfer.

Integer Send(Murl.ConstData data, Integer byteOffset)

Parameters
dataThe data to send.
byteOffsetThe data offset in number of bytes.
Returns
Integer The number of bytes sent from the offset, zero if the data is empty or the data offset is invalid, a negative return value if a socket error occurs.

ReceiveFrom(data, address)

Receive data and the sender address from the socket. This is typically used by sockets connected with ConnectUdpListen().

Boolean, Murl.Data ReceiveFrom(Murl.Data data, Murl.SharedPointer.NetISocketAddress address)

Parameters
dataThe data object to store the incoming data. The data object's byte size is the maximum number of bytes to receive. If the data object is empty a size of 1500 bytes is reserved internally.
addressThe sender address return value.
Returns
Boolean true if successful. The data object is resized to the number of bytes received, otherwise if receive failed the data object is empty.
Murl.Data data The data object to store the incoming data. The data object's byte size is the maximum number of bytes to receive. If the data object is empty a size of 1500 bytes is reserved internally.

SendTo(data, byteOffset, address)

Send data form a specified offset to a specified address. In non-blocking operation this method sends only a portion of data and has to be called in a loop which allows to monitor the data transfer.

Integer SendTo(Murl.ConstData data, Integer byteOffset, Murl.SharedPointer.NetISocketAddress address)

Parameters
dataThe data to send.
byteOffsetThe data offset in number of bytes.
addressThe address to send the data.
Returns
Integer The number of bytes sent from the offset, zero if the data is empty or the data offset is invalid or the address is null, a negative return value if a socket error occurs.

SendTo(data, address)

Send the entire data to a specified address. This is typically used by sockets connected with ConnectUdpBroadcast().

Boolean SendTo(Murl.ConstData data, Murl.SharedPointer.NetISocketAddress address)

Parameters
dataThe data to send.
addressThe address to send the data.
Returns
Boolean true if successful.


Metamethods


The tostring operator

Converts the object content to a string in a reasonable format.

Returns
GetName()