Visual Servoing Platform
version 3.6.1 under development (2024-12-17)
|
#include <visp3/core/vpUDPServer.h>
Public Member Functions | |
vpUDPServer (int port) | |
vpUDPServer (const std::string &hostname, int port) | |
virtual | ~vpUDPServer () |
int | receive (std::string &msg, int timeoutMs=0) |
int | receive (std::string &msg, std::string &hostInfo, int timeoutMs=0) |
int | send (const std::string &msg, const std::string &hostname, int port) |
This class implements a basic (IPv4) User Datagram Protocol (UDP) server.
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 server's code, receiving a basic message and sending an echo message to the client:
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 202 of file vpUDPServer.h.
BEGIN_VISP_NAMESPACE vpUDPServer::vpUDPServer | ( | int | port | ) |
Create a (IPv4) UDP server.
port | : Server port number. |
Definition at line 75 of file vpUDPServer.cpp.
vpUDPServer::vpUDPServer | ( | const std::string & | hostname, |
int | port | ||
) |
Create a UDP server.
hostname | : Server hostname or IP address. |
port | : Server port number. |
Definition at line 91 of file vpUDPServer.cpp.
|
virtual |
Definition at line 101 of file vpUDPServer.cpp.
int vpUDPServer::receive | ( | std::string & | msg, |
int | timeoutMs = 0 |
||
) |
Receive data sent by a client.
msg | : ASCII message or byte data according to the data sent by the client. |
timeoutMs | : Timeout in millisecond (if zero, the call is blocking). |
Definition at line 197 of file vpUDPServer.cpp.
int vpUDPServer::receive | ( | std::string & | msg, |
std::string & | hostInfo, | ||
int | timeoutMs = 0 |
||
) |
Receive data sent by a client.
msg | : ASCII message or byte data according to the data send by the client. |
hostInfo | : Information about the client ("client_name client_ip client_port"). |
timeoutMs | : Timeout in millisecond (if zero, the call is blocking). |
Definition at line 215 of file vpUDPServer.cpp.
int vpUDPServer::send | ( | const std::string & | msg, |
const std::string & | hostname, | ||
int | port | ||
) |
Send data to a client.
msg | : ASCII message or byte data. |
hostname | : Client hostname (hostname or ip address). |
port | : Client port number. |
Definition at line 292 of file vpUDPServer.cpp.
References vpException::fatalError.