IC Python API:RLPy RTcpClient

From Reallusion Wiki!
Jump to: navigation, search
Main article: Modules.

Detailed Description

This class is used to receive TCP/IP data. The Transmission Control Protocol provides reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications running on hosts communicating via an IP network. The RTcpClient is used to receive such data. This class use queue to store the received data. The developer can set the buffer size for storing the maximum data counts by using SetMaximumDataCount(), the default value is 60. When the total data counts received is greater than the maximum buffer counts, the previously received data will be removed. Getting data have to specify index to get the data which developer wants in the buffer and create a container of the same size as the data, then copy data to the container by using GetDataSize() and GetData().

The following is an example to use this class:
data = None
tcp_client = RLPy.RTcpClient()

class NetworkEventCallback(RLPy.RTcpCallback):
 def __init__(self):
   RLPy.RTcpCallback.__init__(self)

 def OnStatusChanged(self, is_connected):
   print(is_connected)

 def OnFailMessageReceived(self, fail_message):
   print(fail_message)
  
 def OnDataReceived(self):
   global data
   global tcp_client
   data = bytearray(tcp_client.GetDataSize(0)) #index 0 => get the first come in data
   tcp_client.GetDataAt(0, data)
   print(data)

  
# Tcp Network
tcp_client.SetMaximumDataCount(100)
network_callback = NetworkEventCallback()
tcp_client.RegisterCallback(network_callback) # register network event callback

tcp_client.Connect("127.0.0.1", 802) # connect to server
print(tcp_client.IsConnected())
...
tcp_client.Disconnect()

Member Functions

Connect

RLPy.RTcpClient.Connect ( self, strIP, uPort )

Connect to server.

Parameters

strIP [IN] IP - string

uPort [IN] Port - int


GetData

RLPy.RTcpClient.GetData ( self, pBuffer )

copy latest data to buffer

Parameters

pBuffer [IN/OUT] buffer - string


GetDataAt

RLPy.RTcpClient.GetDataAt ( self, nIndex, pBuffer )

copy the data to pBuffer according to the specific index

Parameters

pBuffer [IN/OUT] buffer - string

nIndex [IN] current data index in the buffer - int


GetDataCount

RLPy.RTcpClient.GetDataCount ( self )

Get the counts of data in the buffer.

Returns

The counts of data in the buffer - int

GetDataSize

RLPy.RTcpClient.GetDataSize ( self, args )

Get data's size according to the specific index.

Parameters

nIndex [IN] current data index in the buffer - int

Returns

Data size - int

GetMaximumDataCount

RLPy.RTcpClient.GetMaximumDataCount ( self )

return buffer's maximum amount

Returns

Buffer's maximum count - int

IsConnected

RLPy.RTcpClient.IsConnected ( self )

Get the current connection status of the client.

Returns

True if is connecting or False if disconnect - bool

RegisterCallback

RLPy.RTcpClient.RegisterCallback ( self, pCallback )

Register network TCP event callback.

Parameters

pCallback [IN] RTcpCallback - RLPy.RTcpCallback


SendData

RLPy.RTcpClient.SendData ( self, pBuffer, nDataSize )

Write data to the device.

Parameters

pBuffer [IN] buffer - string

nDataSize [IN] Size of data - int

Returns

True if send data success or False if send data fail - bool

SetMaximumDataCount

RLPy.RTcpClient.SetMaximumDataCount ( self, nCount )

Set buffer the maximum amount of received data.

Parameters

nCount [IN] buffer's maximum count - int