XML
You can load XML from file using the “Load XML From File” or “Load XML From File Async”
For larger files it’s recommended to use “Load XML From File Async”
Path is the path to the XML file in standard Windows format
We can then read from the XML document using Find functions:
Example of a use case:
if we have a XML file example:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
</note>
we might want to find who we have the note from
We might also like to find any note from “Jani” and get it’s heading
Notice that we are using the Parent element to get to the <note> element, this can be utilized to go up in the XML hierarchy.
UDP
Allows the connection to the UDP Sockets using blueprints.
There are two main functions: “Open Receiver UDP” to receive UDP messages and “Open Sender UDP” to send UDP messages.
Both accept info
Where you can specify IP, Prot for the socket connection and Socket Name
Receiver UDP
Receiver has a Format dropdown that is used when processing data to string and is used for On Received String
We suggest promoting the receiver to a variable using the “Promote to variable” this will prevent the destruction of the receiver and it will allow later use.
Then we can bind event to the receiver
On Received String interprets the data as a string using the encoding while calling the “Open Receiver UDP”
On Received Data returns raw data without any interpretation and it is for the user to interpret them in some way.
We will use On Received String in this example
We need to bind our event function, we can Add Custom Event
Then we can use the function to interpret the string and do something depending on the string.
In this example we just use Print String to print the message that we have received
Sender UDP
We suggest promoting the sender to a variable using the “Promote to variable” this will prevent the destruction of the sender and it will allow later use.
We can send Messages using the Send function
- Header – text that gets appended before the Massage
- Footer – text that gets appended after the Massage
- Massage – the text that we want to send
- Format – determines the formatting that Massage gets converted to before the send
- Return Value – send returns true if the send has been successful.
Alternatively we can use Send To Prime which is similar to the Send except tries to set Parameter in PRIME
Name – refers to the name of the Parameter in PRIME
Value – value that will be set
Note: it is required to have the Parameter in PRIME scoped to the Project or Application.
In PRIME we can add the listener using the Automation Settings
We use the default settings
Make sure to enable the listener
In VSAR we specify the same port
TCP
TCP Listener
This class implements a frame for TCP server. It listens on a specified port, accepts incoming connections and initializes TCP Connection class for each of them. After default Timeout on connection (one minute), connection is automatically closed and resources freed. If a user wants this behaviour to change, writing custom logic or changing connection attributes is possible by implementing OnTcpConnectionAccepted delegate.
Attributes:
- Info - Socket info, contains socket name, ip address and port number. After changing, calling the Open method is needed.
- ReceiveFormat - This setting will affect encoding of all currently opened connections and all future connections. Supports ANSI, UTF8, UTF16, TCHAR.
Delegates:
- OnTcpReceivedString - invoked on all accepted connections when received message, decodes incoming data to string with specified encoding from ReceiveFormat
- OnTcpReceivedData - invoked on all accepted connections when received message
- OnTcpReceivedStringWithConnection - invoked on all accepted connections when received message, decodes incoming data to string with specified encoding from ReceiveFormat, has second parameter of type TCP Connection, to allow user specifying custom two way communication
- OnTcpReceivedDataWithConnection - invoked on all accepted connections when received message, has second parameter of type TCP Connection, to allow user specifying custom two way communication
- OnTcpConnectionAccepted - invoked immediately after accepting connection, has parameter of type TCP Connection, to allow communication initialization on server side. This should be invoked before first packet processing by above mentioned delegates.
Methods:
- Open - Begins listening on socket specified by Info
- Close - Closes socket
- IsSocketValid - Returns bool, if socket is valid and listening.
TCP Connection
This class implements a frame for TCP client. It is able to receive or send data (or strings, with specified encoding). This class also implements an auto reconnect mechanism, which can be enabled by the user.
Attributes:
- Info - Socket info, contains socket name, ip address and port number. After changing, calling the Open method is needed.
- ReceiveFormat - This setting will affect encoding of all received data. Supports ANSI, UTF8, UTF16, TCHAR.
- Timeout - Time from last socket activity to invoking OnTcpConnectionTimeout delegate. This is supposed to handle closing the socket, if no incoming or outgoing communication goes through. This setting can be changed, if the user wants to have a custom implementation.
- ReconnectTimeout - This attribute can specify a period for the reconnect timer in seconds. The default value is 5 and it is not recommended to set it too low (minimum 2.0). If a reconnect attempt is invoked, with the last one not finished yet, it is skipped.
- AutoReconnect - bool value, enabling auto reconnect mechanism. This should not be set true, on connection created by the listener (but is not checked - responsibility of user) because connections created by listeners are just "mirrors" - hence, they should not reconnect, but wait for the reconnection attempt from the other side.
Delegates:
- OnTcpReceivedString - invoked on all accepted connections when received message, decodes incoming data to string with specified encoding from ReceiveFormat
- OnTcpReceivedData - invoked on all accepted connections when received message
- OnTcpReceivedStringWithConnection - invoked on all accepted connections when received message, decodes incoming data to string with specified encoding from ReceiveFormat, has second parameter of type TCP Connection, to allow user specifying custom two way communication
- OnTcpReceivedDataWithConnection - invoked on all accepted connections when received message, has second parameter of type TCP Connection, to allow user specifying custom two way communication
- OnTcpConnectionTimeout - This delegate is invoked after Timeout amount of time of inactivity - no data sent or received. User is supposed to free resources, close socket and stop using it - since it was not used, there is not a big probability that it will be used in future. Setting the Timeout attribute can change the delay of invoking this delegate. Also, not implementing it is not a mistake and can be done - but, there will be a socket and some additional resources allocated and reserved.
- OnTcpConnectionFailed - This delegate is invoked, after an Open method was called, but connection was not successful. If AutoReconnect is set, reconnection will be attempted, if not, the user can implement its own logic, using this delegate.
- OnTcpConnected - This delegate is invoked, after a successful connection attempt. If a user wants to send any data through connection, implementation should be done after this event. (because before this, socket is not valid and all sending attempts will result in fail)
Methods:
- Open - Attempts to connect to socket, specified in Info.
- Close - Closes socket and frees any resources.
- IsSocketValid - Checks if socket is allocated. Does not care about state of connection.
- IsConnected - Checks if socket is allocated, connected and if connection is not timeouted.
- SendString - Sends string with specified encoding (set as parameter, defaults to UTF8)
- SendBytes - Sends bytes
- GetSocketInfo - Returns Info
Opening functions:
- OpenListenerTCP
Open TCP listener. Listener can be used immediately after this function is executed. Recommended to check if socket is valid after initialization. Afterwards users can bind custom events to delegates.
- OpenConnectionTCP