Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Data transfer in network over Sockets

The communication over the sockets in the PROMOTIC system is now regarded as the oldest method of a data transfer and it was replaced by the simpler and more transparent communication using XML, see the description: XML data sharing.

The socket communication serves first of all for a data exchange between applications in the network.

The model client-server is used for the communication in the network. This means first of all that the user must define two (or more) applications that will communicate to each other and decide which of the applications will provide an access to its data and which of the applications will access these data (read or write). If the application provides the data for the usage, this application is of the SERVER type, if the application accesses other (provisioned) data, this application is of the KLIENT type. Practically it means that we define so called server socket groups in the PROMOTIC server application, and that we define client socket groups in the PROMOTIC client application.

While at the server socket group only its name and operational parameters are defined, client socket group says which nodal PC will be communicated with and which server group will be referenced from this client group.

The user defines the client part of the communication thereby that it creates client socket groups on the page PmRoot > Sockets. The client is here specified by the address of the destination PC and by the name of the server group.

The server part of the communication is analogously defined by the creation of client server groups on the same page.

The communication itself is implemented by means of the PmData Promotic object that is located into one of the defined (client or server) groups at the configuration and the transfer is initialized by the methods PmData.ReadFromSocket or PmData.WriteToSocket.

Caution: The socket communication is licensed in the PROMOTIC system, i.e. for its running in the runtime (with a runtime license), it is necessary to purchase an item for the network clients of the "PmDataClient" type. The license must be purchased only when the server socket group is defined in the application and so many licenses must be purchased how many clients the application is supposed to communicate at the most. In the development environment the socket communication functions automatically for testing 5 clients at the most.

 
Two types of the network protocol can be used for the transfer:
1. TCP protocol that enables to transfer the unlimited size of data as well as to check the correct sequence and to control the data and the connection. But establishing the connection with the target PC isn't so quick as for the UDP protocol.
2. UDP protocol that enables very quick establishing the connection but the length of the transferred data is limited to 512 bytes. In the Transfer type configurator of the Socket server group window it is the item "Limited data length UDP/IPX".

Both types of the protocol are used in the PROMOTIC system by default in such a way that at first the PROMOTIC head is sent and then the transferred data follows. There is a data identifier in the head that serves for the unambiguous determination of the data on the target side. This unambiguous determination is given by the "Item" item name in the socket configuration at the data (see the page PmData > Sockets). Thus standard socket messages are wrapped up in the head and that's why only PROMOTIC applications can be connected to each other using this type of the communication by default.

 
UDP without PROMOTIC head:

To enable sending any user data over the sockets, a subtype of the UDP communication was created - UDP without PROMOTIC head. By this type of the communication it is possible to transfer any data defined in the data object. As the PROMOTIC system doesn't add anything to these data, the designer can construct exactly such data that are requested by the application on the other side.

Bytes of the Integer and Long data types are sent in the reverse order than on the PC (at first the HIGH and then the LOW byte). Thus sent format of Integer and Long values (so called Big Endian) is a standard namely in the Socket communication. If it is required to send these values in the PC format (so called Little Endian) then the text "e=L;" has to be written into the item PmData > Sockets > Item. Otherwise this item should be blank (as the head isn't sent, this item doesn't serve for the data identification).

When choosing this type of the transfer a server object (i.e. an object connected to the server socket group) can only receive data and a client object can only send data and thus only the WriteToSocket method can be called. But there can be more server objects (i.e. objects that receive data from sockets) and thus a mechanism must exist that recognizes on the data receipt what a data object this message belongs to. For this purpose it is necessary to consider the first three items as the system ones at server data objects and the received message is stored only into the next items. Now we'll describe the form of these three system items:

0.item (let's call it PM_enable) must be of the Integer type. The value 0 means that this object now doesn't receive, 1 that it receives. The value can be dynamically changed.
1.item (let's call it PM_id) must by of the String type. The value defines if the received data belongs to this object (provided that it isn't inhibited by 0.item). The value consists of a text that has the form, for example: "l=24;b3=235;b7=4;". In this case it means that received data belongs to this object only when its length is 24 bytes (l=24, l as length), the third byte has the value 235 (b3=235, b as byte) and the seventh byte has the value 4 (b7=4). While each item is terminated by a semicolon (;), the "bx=y;" definition can occur more than one time and if the whole text is empty, then it means the received message belongs always to this object if no other data object with a non-empty text wants it.
2.item (let's call it PM_size) must be of the Long type. If the message belongs to this object, then the received data are placed into items after three system items. Then a number of data items that were filled by the message, is stored into the 2.item.
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice