Visual Servoing Platform
version 3.2.0 under development (2019-01-22)
|
#include <visp3/core/vpUDPClient.h>
Public Member Functions | |
vpUDPClient (const std::string &hostname, const int port) | |
virtual | ~vpUDPClient () |
int | receive (std::string &msg, const int timeoutMs=0) |
int | send (const std::string &msg) |
This class implements a basic (IPv4) User Datagram Protocol (UDP) client.
More information here, here or here:
This User Datagram Protocol (UDP) is defined to make available a datagram mode of packet-switched computer communication in the environment of an interconnected set of computer networks. This protocol assumes that the Internet Protocol (IP) [1] is used as the underlying protocol.
This protocol provides a procedure for application programs to send messages to other programs with a minimum of protocol mechanism. The protocol is transaction oriented, and delivery and duplicate protection are not guaranteed. Applications requiring ordered reliable delivery of streams of data should use the Transmission Control Protocol (TCP) [2].
Example of a client's code, sending a basic message and receiving the server answer:
If you want to send a complex data type, you can either send the ASCII representation or send directly the byte data. In the last case, you should have to handle that both the server and the client have the same data type representation. Be careful also with the endianness of the network / host.
Here an example using a structure of data, assuming that both the server and the client have the same architecture (probably you should write your own serialization / deserialization functions for the data you want to send / receive):
Definition at line 168 of file vpUDPClient.h.
vpUDPClient::vpUDPClient | ( | const std::string & | hostname, |
const int | port | ||
) |
Create a (IPv4) UDP client.
hostname | : Server hostname or IP address. |
port | : Server port number. |
Definition at line 67 of file vpUDPClient.cpp.
|
virtual |
Definition at line 77 of file vpUDPClient.cpp.
References vpException::fatalError.
int vpUDPClient::receive | ( | std::string & | msg, |
const int | timeoutMs = 0 |
||
) |
Receive data sent by the server.
msg | : ASCII message or byte data. |
timeoutMs | : Timeout in millisecond (if zero, the call is blocking). |
Definition at line 160 of file vpUDPClient.cpp.
int vpUDPClient::send | ( | const std::string & | msg | ) |
Send data to the server.
msg | : ASCII message or byte data. |
Definition at line 218 of file vpUDPClient.cpp.