HSL2.0 - Network: TCP and HTTP
Content
1.
Client (outgoing connection)
2.
Server (incoming connection)
2.1.
Firmware version 4.5 (HTTP only)
2.2.
Firmware version >= 4.7
Description of the differences when using firmware 4.5 on the one hand, and firmware 4.7 or later on the other

## 1.Client (outgoing connection)

If the logic module contains a functionality of a network client (e.g. data retrieval via http), all firmware versions behave the same.

## 2.Server (incoming connection)

If the module contains a functionality of a server or expects incoming network connections, the firmware version 4.5 behaves differently to the versions 4.7. and newer.

### 2.1.Firmware version 4.5 (HTTP only)

The access to the network is not restricted by the firmware for the logic module. It can open any port (which has not yet been occupied by the firmware). The developer of the device must ensure that the commissioning engineer in the HS project can ensure that the used ports of the firmware or the project and the device (or other devices) do not overlap, i.e. that no port is occupied twice. This can be done, for example, by using an input that defines the port number.
Example:

    01  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    02  s.bind(('', self.PIN_I_PORT))
    03  s.listen(1)
    04  conn, addr = s.accept()

### 2.2.Firmware version >= 4.7

With the introduction of secure communication via HTTPS/TLS, it is possible for the firmware to forward HTTPS communication. In the expert, a base path and an internal port can be assigned to the block during configuration. The firmware forwards all HTTP(S) requests on this path to the internal port. The block must listen at this internal port. The module does not have to worry about the encryption by TLS/SSL. The firmware forwards the HTTP communication decrypted to the module.
To configure the corresponding base path and the internal port, there are the input types base_path and destination_port for the logic module.
Both input types can only be assigned as constants to the input of the logic module. The input of type base_path must always receive a valid value/path. The input of the type destination_port can be optionally set or assigned 0. If it is set to 0, the expert assigns it a valid value or free port when transferring the project.
There is also the possibility of HTTP access, if this has been configured in the expert. In this case, communication with the HS/FS is no longer encrypted, but this makes no difference for the use of the interface.
Example config.xml:

    01 <?xml version="1.0" encoding="UTF-8"?>
    02 <config>
    03     <modules>
    04         <module category="examples" context="examples" id="10978" name="HTTP_API" version="1.0">
    05             <inputs>
    06                 <input type="base_path" init_value="/http_api">Base-Path</input>
    07                 <input type="destination_port" init_value="0">Port</input>
    08             </inputs>
    09             <outputs>
    10                 <output type="number" init_value="0">Output value 1</output>
    11                 <output type="number" init_value="0">Output value 2</output>
    12             </outputs>
    13             <remanent_variables>
    14             </remanent_variables>
    15             <imports>
    16                 <import>hsl20_4_debug_page</import>
    17                 <import>thread</import>
    18                 <import>socket</import>
    19             </imports>
    20         </module>
    21     </modules>
    22 </config>

Example section:

    01 ...
    02 def on_init(self):
    03     self.debug_section = self.FRAMEWORK.create_debug_section()
    04     self.debug_section.add_message("on_init")
    05     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    06     s.bind(('127.0.0.1', int(self._get_input_value(self.PIN_I_PORT))))
    07     s.listen(1)
    08     conn, addr = s.accept()
    09     self.debug_section.add_message('Connection address: ' + addr)
    10 ...