Visual Servoing Platform
version 3.1.0
|
#include <visp3/core/vpUDPServer.h>
Public Member Functions | |
vpUDPServer (const int port) | |
vpUDPServer (const std::string &hostname, const int port) | |
~vpUDPServer () | |
int | receive (std::string &msg, const int timeoutMs=0) |
int | receive (std::string &msg, std::string &hostInfo, const int timeoutMs=0) |
int | send (const std::string &msg, const std::string &hostname, const 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 194 of file vpUDPServer.h.
vpUDPServer::vpUDPServer | ( | const int | port | ) |
Create a (IPv4) UDP server.
port | : Server port number. |
Definition at line 61 of file vpUDPServer.cpp.
vpUDPServer::vpUDPServer | ( | const std::string & | hostname, |
const int | port | ||
) |
Create a UDP server.
hostname | : Server hostname or IP address. |
port | : Server port number. |
Definition at line 77 of file vpUDPServer.cpp.
vpUDPServer::~vpUDPServer | ( | ) |
Definition at line 87 of file vpUDPServer.cpp.
References vpException::fatalError.
int vpUDPServer::receive | ( | std::string & | msg, |
const 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 182 of file vpUDPServer.cpp.
int vpUDPServer::receive | ( | std::string & | msg, |
std::string & | hostInfo, | ||
const 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 200 of file vpUDPServer.cpp.
int vpUDPServer::send | ( | const std::string & | msg, |
const std::string & | hostname, | ||
const 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 275 of file vpUDPServer.cpp.
References vpException::fatalError.