Skip to content

TCP Server Interaction

Currently, only TCP servers can be created on ResIOT. Soon, we will also support UDP servers.
The only way to interact with TCP servers created over ResIOT is via LUA scripting.
Each connection is assigned a random UniqueID generated during connection time.
Interacting with a connected client requires the connector ID and the connection UniqueID.


Name Input Params Return Data Description
resiot_tcpudpserver_writebytes String, String, BYTE [] String Send a byte array to the client
resiot_tcpudpserver_writestring String, String, String String Sends text to the client
resiot_tcpudpserver_connection_get String, String String, String Retrieve information about an open connection
resiot_tcpudpserver_connections_get String String, String Get the list of open connections over a TCP Server
resiot_tcpudpserver_connection_close String, String String Kills an existing connection
resiot_tcpudpserver_read String, String String, String Reads the current data buffer of a TCP client

resiot_tcpudpserver_writebytes(String, String, BYTE[])

Writes a byte array over an open TCP connection.
Example
err = resiot_tcpudpserver_writebytes (connectorId, connectionUniqueID, data)
Input Parameters
 - Connector ID (String): * The HexID of your connector.
 - Connection Unique ID (String): * The connection Unique ID assigned to the TCP open connection.

 - Data (BYTE[]): * The data to be transmitted to the client.
Returns
 - Error (String): * A string containing the error message. If the string is empty, no error occurred.

connectorId = "636f6e34"
connectionId = "c016c72ad1498a3b
downlink = {0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x64, 0x06, 0x00, 0x05, 0x00, 0x06}
err = resiot_tcpudpserver_writebytes(connectorId, connectionId, data)
if err ~= "" then
    resiot_debug(err)  
end

Return to index


resiot_tcpudpserver_writestring(String, String, String)

Writes a byte array over an open TCP connection.
Example
err = resiot_tcpudpserver_writestring(connectorId, connectionUniqueID, data)
Input Parameters
 - Connector ID (String): * The HexID of your connector.
 - Connection Unique ID (String): * The connection Unique ID assigned to the TCP open connection.

 - Data (String): * The data to be transmitted to the client.
Returns
 - Error (String): * A string containing the error message. If the string is empty, no error occurred.

connectorId = "636f6e34"
connectionId = "c016c72ad1498a3b
downlink = "test"
err = resiot_tcpudpserver_writestring(connectorId, connectionId, data)
if err ~= "" then
    resiot_debug(err)  
end

Return to index


resiot_tcpudpserver_connection_get(String, String)

Retrieves information about an open connection.
Example
info, err = resiot_tcpudpserver_connection_get(connectorId, connectionUniqueID)
Input Parameters
 - Connector ID (String): * The HexID of your connector.
 - Connection Unique ID (String): * The connection Unique ID assigned to the TCP open connection.

Returns
 - Info (String): * A JSON with all the connection information.
 - Error (String): * A string containing the error message. If the string is empty, no error occurred.

TODO:connectorId = "636f6e34"
connectionId = "c016c72ad1498a3b"
data, err = resiot_tcpudpserver_connection_get(connectorId, connectionId)
if err ~= "" then
    resiot_debug(err)  
end
resiot_debug(data) --{"data":[{"Connector":"636f6e34","ConnectionId":"5aa268b888a8ef04","ServerInstance":1,"RemoteHost":"188.206.76.109:22016","ServerHost":"172.19.0.6:53000","Uptime":904.257201134}]}

Return to index


resiot_tcpudpserver_connections_get(String)

Retrieves the list of uniqueIDs of the open connections over your TCP server.
Example
connections, err = resiot_tcpudpserver_connections_get(connectorId)
Input Parameters
 - Connector ID (String): * The HexID of your connector.
Returns
 - Info (String): * A JSON with the list of uniqueIDs of the open connections over your TCP server.

 - Error (String): * A string containing the error message. If the string is empty, no error occurred. *

connectorId = "636f6e34"
connectionId = "5aa268b888a8ef04"
data, err = resiot_tcpudpserver_connections_get(connectorId)
if err ~= "" then
    resiot_debug(err)  
end
resiot_debug(data) --{"data":[{"Connector":"636f6e34","ConnectionId":"5aa268b888a8ef04","ServerInstance":1,"RemoteHost":"188.206.76.109:22016","ServerHost":"170.19.0.6:53000","Uptime":891.709035635}]}

Return to index


resiot_tcpudpserver_connection_close(String, String, String)

Kills an open connection.
Example
err = resiot_tcpudpserver_connection_close(connectorId, connectionUniqueID)
Input Parameters
 - Connector ID (String): * The HexID of your connector.
 - Connection Unique ID (String): * The connection Unique ID assigned to the TCP open connection.

Returns
 - Error (String): * A string containing the error message. If the string is empty, no error occurred. *

connectorId = "636f6e34"
connectionId = "c016c72ad1498a3b
err = resiot_tcpudpserver_connection_close(connectorId, connectionId)
if err ~= "" then
    resiot_debug(err)  
end

Return to index


resiot_tcpudpserver_read(String, String)

Reads the current data buffer of a TCP client.
Example
data, err = resiot_tcpudpserver_read(connectorId, connectionUniqueID)
Input Parameters
 - Connector ID (String): * The HexID of your connector.
 - Connection Unique ID (String): * The connection Unique ID assigned to the TCP open connection.

Returns
 - Data (String): * the unread data buffer sent by the client over the connection.
 - Error (String): * A string containing the error message. If the string is empty, no error occurred.

connectorId = "636f6e34"
connectionId = "5aa268b888a8ef04"
data, err = resiot_tcpudpserver_read(connectorId, connectionId)
if err ~= "" then
    resiot_debug(err)  
end
resiot_debug(data) --prints any data sent by the client that hasn't been read yet

Return to index