HSL 2.0 framework
Description of the framework
Public Member Functions |List of all members
hsl20_4_udp.hsl20_4_udp.Unicast Class Reference

All methods for communication via UDP-Unicast More..

.

Inherits hsl20_4_udp.hsl20_4_udp.UdpBase

Public Member Functions

defset_address (self, ip, port)
Sets the address where data can be received. More...
defsend_to (self, data, ip, port)
Sends data to the specified address. More...
-Public Member Functions inherited from hsl20_4_udp.hsl20_4_udp.UdpBase
def__init__(self, framework, context_map)
Constructor. More...
defset_on_data (self, callback)
Sets a callback for data reception. More...
defset_on_error (self, callback)
Sets a callback in case of an error. More...
defstart_server (self)
Starts the UDP receive server. More...

Detailed Description

All methods for communication via UDP-Unicast

Deprecated:
This class should no longer be used

Provides communication via UDP/IP in both directions.

Is derived from UdpBase.

Example 1

class UDP_Server(hsl20_4.BaseModule):
def __init__(self, homeserver_context):
...
def on_init(self):
self.server=None
def on_input_value(self, index, value):
if index == self.PIN_I_START:
if self.server == None:
self.server = self.FRAMEWORK.create_udp_unicast()
self.server.set_address("" , int(self._get_input_value(self.PIN_I_PORT))
self.server.set_on_data(self.on_data)
self.server.start_server()
def on_data(self, data, addr):
self._set_output_value(self.PIN_O_RECV_DATA, data)

In example 1, a UDP server is started when a telegram arrives at input 1 (PIN_I_START). This server listens on the port which is defined by input 2 (PIN_I_PORT). All UDP telegrams arriving on this port are output on output 1 (PIN_O_RECV_DATA).

Example 2

class UDP_Client(hsl20_4.BaseModule):
def __init__(self, homeserver_context):
...
def on_init(self):
self.client=None
def on_input_value(self, index, value):
if index == self.PIN_I_DATA:
if self.client == None:
self.client = self.FRAMEWORK.create_udp_unicast()
self.client.send_to(value, self._get_input_value(self.PIN_I_IP), int(self._get_input_value(self.PIN_I_PORT))

Example 2 contains a simple UDP client. If a telegram arrives at input 1 (PIN_I_DATA), it is sent via UDP. The target computer is determined via inputs 2 (PIN_I_IP) and 3 (PIN_I_PORT).

Note
The class works asynchronously. None of the methods offered are blocked

Member Function Documentation

◆ send_to()

def hsl20_4_udp.hsl20_4_udp.Unicast.send_to ( self,
data,
ip,
port
)

Sends data to the specified address

Parameters
datastring
Data
ipstring
IP address of the destination
portint
IP port of the destination

◆ set_address()

def hsl20_4_udp.hsl20_4_udp.Unicast.set_address ( self,
ip,
port
)

Sets the address at which data can be received

Parameters
ipstring
IP address. If an empty string is specified, the data is received at the HomeServer network address
portint
IP port where the data can be received and sent
Exceptions
RuntimeError
If this method is called while the server is already started, a RuntimeError exception is thrown

The documentation for this class was generated from the following file: