Difference between revisions of "IC Python API:RLPy RUdpCallback"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} ==Inheritance== This class inherits public member functions from: *RLPy.RCallback =...")
 
m
 
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
==Inheritance==
+
{{last_modified}}
This class inherits public member functions from:
+
 
*[[IC_Python_API:RLPy_RCallback|RLPy.RCallback]]
+
== Description ==
==Detailed Description==
+
 
This class is used to register callbacks for UDP network.
+
This class is used to monitor UDP connection status and recieve connection data.
==Member Functions==
+
 
===OnStatusChanged===
+
=== Inheritance ===
<syntaxhighlight lang="Python">
+
 
RLPy.RUdpCallback.OnStatusChanged ( self, bIsConnected )
+
[[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>
Callback function when status changed.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''bIsConnected''' [IN] connected or not - bool
+
=== OnDataReceived ( self ) ===
</div>
+
 
 +
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."