IC Python API:RLPy RTcpCallback

From Reallusion Wiki!
Jump to: navigation, search
Main article: Modules.
Last modified: 04/22/2020

Description

This class is used to monitor TCP/IP connection status and recieve connection data.

Inheritance

RCallback > RTcpCallback

Member Functions

OnStautsChange ( self, bIsConnected )

The application will call this function when there is a change in connection status; In which case, the new status message will be given.

Parameters

bIsConnected [OUT] connected or not - bool
 1 tcp_client = RLPy.RTcpClient()
 2 
 3 class NetworkEventCallback(RLPy.RTcpCallback):
 4    def __init__(self):
 5        RLPy.RTcpCallback.__init__(self)
 6   
 7    def OnStatusChanged(self, is_connected):
 8        print(is_connected)
 9 
10 network_callback = NetworkEventCallback()
11 
12 # register network event callback
13 tcp_client.RegisterCallback(network_callback)
14 
15 # connect to server   
16 tcp_client.Connect("127.0.0.1", 802) 
17 # if connect success, will print "True", otherwise print "False"

OnDataReceived ( self )

The application will call this function when a connection has been made and once the data has been received. Once this has been achieved, RLPy.RTcpClient.GetDataSize() can be used to establish a sized buffer ready to recieve the incoming data via RLPy.RTcpClient.GetDataAt().

See Also: RTcpClient, RLPy.RTcpClient.GetData(), RLPy.RTcpClient.GetDataAt(), RLPy.RTcpClient.GetDataSize()

 1 tcp_client = RLPy.RTcpClient()
 2 
 3 class NetworkEventCallback(RLPy.RTcpCallback):
 4    def __init__(self):
 5        RLPy.RTcpCallback.__init__(self)
 6   
 7    def OnDataReceived(self):
 8        global data
 9        global tcp_client
10        data = bytearray(tcp_client.GetDataSize(0))       
11        #index 0 => get the first come in data
12        tcp_client.GetDataAt(0, data) 
13        print(data)
14 
15 network_callback = NetworkEventCallback()
16 # register network event callback
17 tcp_client.RegisterCallback(network_callback)
18 # connect to server   
19 tcp_client.Connect("127.0.0.1", 802) 
20 # if connect success, will print "True", otherwise print "False"

OnFailMessageReceived ( self, pErrorMsg )

This function is called by the application in the event that a connection can not be established or a connection error has occurred; In which case, an error message will be given.

Parameters

pErrorMsg [IN] connect fail error message - string
 1 tcp_client = RLPy.RTcpClient()
 2 
 3 class NetworkEventCallback(RLPy.RTcpCallback):
 4    def __init__(self):
 5        RLPy.RTcpCallback.__init__(self)
 6   
 7    def OnFailMessageReceived(self, fail_message):
 8        print(fail_message)
 9 
10 network_callback = NetworkEventCallback()
11 # register network event callback
12 tcp_client.RegisterCallback(network_callback)
13 # connect to server   
14 tcp_client.Connect("127.0.0.1", 802) 
15 # if connect failed, will print "Couldn't connect to server."