Visual Servoing Platform
version 3.5.1 under development (2023-09-22)
|
#include <visp3/core/vpUDPClient.h>
Public Member Functions | |
vpUDPClient () | |
vpUDPClient (const std::string &hostname, int port) | |
virtual | ~vpUDPClient () |
Inherited functionalities from vpUDPClient | |
bool | m_is_init |
void | init (const std::string &hostname, int port) |
int | receive (std::string &msg, int timeoutMs=0) |
int | receive (void *msg, size_t len, int timeoutMs=0) |
int | send (const std::string &msg) |
int | send (const void *msg, size_t len) |
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 166 of file vpUDPClient.h.
vpUDPClient::vpUDPClient | ( | ) |
Default constructor.
Use connect() to establish the connexion with the server.
Definition at line 66 of file vpUDPClient.cpp.
vpUDPClient::vpUDPClient | ( | const std::string & | hostname, |
int | port | ||
) |
Create a (IPv4) UDP client.
hostname | : Server hostname or IP address. |
port | : Server port number. |
Definition at line 81 of file vpUDPClient.cpp.
References init().
|
virtual |
Destructor.
Definition at line 94 of file vpUDPClient.cpp.
void vpUDPClient::init | ( | const std::string & | hostname, |
int | port | ||
) |
Initialize a (IPv4) UDP client.
hostname | : Server hostname or IP address. |
port | : Server port number. |
Definition at line 118 of file vpUDPClient.cpp.
References vpException::fatalError, and m_is_init.
Referenced by vpUDPClient().
int vpUDPClient::receive | ( | std::string & | msg, |
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 195 of file vpUDPClient.cpp.
References m_is_init, and vpException::notInitialized.
Referenced by vpForceTorqueAtiNetFTSensor::waitForNewData().
int vpUDPClient::receive | ( | void * | msg, |
size_t | len, | ||
int | timeoutMs = 0 |
||
) |
Receive data sent by the server.
msg | : A message to send over the network. |
len | : Message length. |
timeoutMs | : Timeout in millisecond (if zero, the call is blocking). |
Definition at line 241 of file vpUDPClient.cpp.
References m_is_init, and vpException::notInitialized.
int vpUDPClient::send | ( | const std::string & | msg | ) |
Send data to the server.
msg | : ASCII message or byte data. |
Definition at line 301 of file vpUDPClient.cpp.
References m_is_init, and vpException::notInitialized.
Referenced by vpForceTorqueAtiNetFTSensor::startStreaming(), and vpForceTorqueAtiNetFTSensor::stopStreaming().
int vpUDPClient::send | ( | const void * | msg, |
size_t | len | ||
) |
Send data to the server.
msg | : Message to send. |
len | : Message length. |
Definition at line 330 of file vpUDPClient.cpp.
References m_is_init, and vpException::notInitialized.
|
protected |
Definition at line 184 of file vpUDPClient.h.
Referenced by vpForceTorqueAtiNetFTSensor::bias(), vpForceTorqueAtiNetFTSensor::getForceTorque(), init(), receive(), send(), vpForceTorqueAtiNetFTSensor::startStreaming(), vpForceTorqueAtiNetFTSensor::stopStreaming(), and vpForceTorqueAtiNetFTSensor::waitForNewData().