Difference between revisions of "IC Python API:RLPy RUdpCallback"
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 UDP connection status and recieve connection data. | |
− | == | + | |
− | === | + | === Inheritance === |
− | <syntaxhighlight lang=" | + | |
− | RLPy.RUdpCallback.OnStatusChanged ( self, | + | [[IC_Python_API:RLPy_RCallback|RCallback]]> [[IC_Python_API:RLPy_RUdpCallback|RUdpCallback]] |
+ | |||
+ | == Member Functions == | ||
+ | |||
+ | === OnStatusChanged ( 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'> | ||
+ | udp_client = RLPy.RUdpClient() | ||
+ | |||
+ | class NetworkEventCallback(RLPy.RUdpCallback): | ||
+ | def __init__(self): | ||
+ | RLPy.RUdpCallback.__init__(self) | ||
+ | |||
+ | def OnStatusChanged(self, is_connected): | ||
+ | print(is_connected) | ||
+ | |||
+ | network_callback = NetworkEventCallback() | ||
+ | # register network event callback | ||
+ | udp_client.RegisterCallback(network_callback) | ||
+ | # connect to server | ||
+ | udp_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_RUdpClient|RUdpClient]], [[IC_Python_API:RLPy_RUdpClient#GetData|RLPy.RUdpClient.GetData()]], [[IC_Python_API:RLPy_RUdpClient#GetDataAt|RLPy.RUdpClient.GetDataAt()]], [[IC_Python_API:RLPy_RUdpClient#GetDataSize|RLPy.RUdpClient.GetDataSize()]] | ||
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
+ | udp_client = RLPy.RUdpClient() | ||
+ | |||
+ | class NetworkEventCallback(RLPy.RUdpCallback): | ||
+ | def __init__(self): | ||
+ | RLPy.RUdpCallback.__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 | ||
+ | udp_client.RegisterCallback(network_callback) | ||
+ | # connect to server | ||
+ | udp_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'> | ||
+ | udp_client = RLPy.RUdpClient() | ||
+ | |||
+ | class NetworkEventCallback(RLPy.RUdpCallback): | ||
+ | def __init__(self): | ||
+ | RLPy.RUdpCallback.__init__(self) | ||
+ | |||
+ | def OnFailMessageReceived(self, fail_message): | ||
+ | print(fail_message) | ||
+ | |||
+ | network_callback = NetworkEventCallback() | ||
+ | # register network event callback | ||
+ | udp_client.RegisterCallback(network_callback) | ||
+ | # connect to server | ||
+ | udp_client.Connect("127.0.0.1", 802) | ||
+ | # if connect failed, will print "Couldn't connect to server." | ||
+ | </syntaxhighlight> |
Latest revision as of 22:13, 22 April 2020
- Main article: Modules.
- Last modified: 04/22/2020
Description
This class is used to monitor UDP connection status and recieve connection data.
Inheritance
RCallback> RUdpCallback
Member Functions
OnStatusChanged ( 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 udp_client = RLPy.RUdpClient()
2
3 class NetworkEventCallback(RLPy.RUdpCallback):
4 def __init__(self):
5 RLPy.RUdpCallback.__init__(self)
6
7 def OnStatusChanged(self, is_connected):
8 print(is_connected)
9
10 network_callback = NetworkEventCallback()
11 # register network event callback
12 udp_client.RegisterCallback(network_callback)
13 # connect to server
14 udp_client.Connect("127.0.0.1", 802)
15 # 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: RUdpClient, RLPy.RUdpClient.GetData(), RLPy.RUdpClient.GetDataAt(), RLPy.RUdpClient.GetDataSize()
1 udp_client = RLPy.RUdpClient()
2
3 class NetworkEventCallback(RLPy.RUdpCallback):
4 def __init__(self):
5 RLPy.RUdpCallback.__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 udp_client.RegisterCallback(network_callback)
18 # connect to server
19 udp_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 udp_client = RLPy.RUdpClient()
2
3 class NetworkEventCallback(RLPy.RUdpCallback):
4 def __init__(self):
5 RLPy.RUdpCallback.__init__(self)
6
7 def OnFailMessageReceived(self, fail_message):
8 print(fail_message)
9
10 network_callback = NetworkEventCallback()
11 # register network event callback
12 udp_client.RegisterCallback(network_callback)
13 # connect to server
14 udp_client.Connect("127.0.0.1", 802)
15 # if connect failed, will print "Couldn't connect to server."