Difference between revisions of "IC Python API:RLPy RTcpCallback"
Chuck (RL) (Talk | contribs) (Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} ==Inheritance== This class inherits public member functions from: *RLPy.RCallback =...") |
Chuck (RL) (Talk | contribs) m |
||
| Line 1: | Line 1: | ||
{{TOC}} | {{TOC}} | ||
{{Parent|IC_Python_API:RL_Python_Modules|Modules}} | {{Parent|IC_Python_API:RL_Python_Modules|Modules}} | ||
| − | == | + | {{last_modified}} |
| − | This class | + | |
| − | + | == Description == | |
| − | == | + | |
| − | + | This class is used to monitor TCP/IP connection status and recieve connection data. | |
| − | == | + | |
| − | === | + | === Inheritance === |
| − | <syntaxhighlight lang=" | + | |
| − | RLPy.RTcpCallback.OnStatusChanged ( self, | + | [[IC_Python_API:RLPy_RCallback|RCallback]] > [[IC_Python_API:RLPy_RTcpCallback|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 | ||
| + | |||
| + | <syntaxhighlight lang="python" line='line'> | ||
| + | tcp_client = RLPy.RTcpClient() | ||
| + | |||
| + | class NetworkEventCallback(RLPy.RTcpCallback): | ||
| + | def __init__(self): | ||
| + | RLPy.RTcpCallback.__init__(self) | ||
| + | |||
| + | def OnStatusChanged(self, is_connected): | ||
| + | print(is_connected) | ||
| + | |||
| + | network_callback = NetworkEventCallback() | ||
| + | |||
| + | # register network event callback | ||
| + | tcp_client.RegisterCallback(network_callback) | ||
| + | |||
| + | # connect to server | ||
| + | tcp_client.Connect("127.0.0.1", 802) | ||
| + | # if connect success, will print "True", otherwise print "False" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | |||
| − | |||
| − | |||
| − | ''' | + | === 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, [[IC_Python_API:RLPy_RTcpClient#GetDataSize|RLPy.RTcpClient.GetDataSize()]] can be used to establish a sized buffer ready to recieve the incoming data via [[IC_Python_API:RLPy_RTcpClient#GetDataAt|RLPy.RTcpClient.GetDataAt()]]. | ||
| + | |||
| + | See Also: [[IC_Python_API:RLPy_RTcpClient|RTcpClient]], [[IC_Python_API:RLPy_RTcpClient#GetData|RLPy.RTcpClient.GetData()]], [[IC_Python_API:RLPy_RTcpClient#GetDataAt|RLPy.RTcpClient.GetDataAt()]], [[IC_Python_API:RLPy_RTcpClient#GetDataSize|RLPy.RTcpClient.GetDataSize()]] | ||
| + | |||
| + | <syntaxhighlight lang="python" line='line'> | ||
| + | tcp_client = RLPy.RTcpClient() | ||
| + | |||
| + | class NetworkEventCallback(RLPy.RTcpCallback): | ||
| + | def __init__(self): | ||
| + | RLPy.RTcpCallback.__init__(self) | ||
| + | |||
| + | 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) | ||
| + | |||
| + | network_callback = NetworkEventCallback() | ||
| + | # register network event callback | ||
| + | tcp_client.RegisterCallback(network_callback) | ||
| + | # connect to server | ||
| + | tcp_client.Connect("127.0.0.1", 802) | ||
| + | # if connect success, will print "True", otherwise print "False" | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | === 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 | ||
| + | |||
| + | <syntaxhighlight lang="python" line='line'> | ||
| + | tcp_client = RLPy.RTcpClient() | ||
| + | |||
| + | class NetworkEventCallback(RLPy.RTcpCallback): | ||
| + | def __init__(self): | ||
| + | RLPy.RTcpCallback.__init__(self) | ||
| + | |||
| + | def OnFailMessageReceived(self, fail_message): | ||
| + | print(fail_message) | ||
| + | |||
| + | network_callback = NetworkEventCallback() | ||
| + | # register network event callback | ||
| + | tcp_client.RegisterCallback(network_callback) | ||
| + | # connect to server | ||
| + | tcp_client.Connect("127.0.0.1", 802) | ||
| + | # if connect failed, will print "Couldn't connect to server." | ||
| + | </syntaxhighlight> | ||
Latest revision as of 20:42, 22 April 2020
- 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."