Class provinding an UDP client able to communicate over the ethernet with a server identified by its IP address trougth a determined port. To use this class, add the -udp aaa.aaa.aaa.aaa pppp option to the move3d exectutable with a the server ip address and p the port number. After, include the Util-pkg.h. Use then in your functions the global variable "UdpClient * globalUdpClient". To send a message use globalUdpClient->send(std::string("message"));. To receive message use globalUdpClient->receive();. TODO The receive fonction is a blocant one (i.e. the program wait until there is a data comming from the server). To set it non blocant (i.e. the program do not wait. You have to integrate the reveice method into a loop to check if there is a message or not), use the function globalUdpClient->setblocant(false);.
More...
#include <UdpClient.h>
List of all members.
Public Member Functions |
| UdpClient (std::string serverIp, int port) |
| Class constructor. Take the server ip address and the port to establish the connection.
|
virtual | ~UdpClient () |
| Class destructor. Close the connection with the server.
|
void | send (std::string &message) |
| Send a text message to the server.
|
std::string | receive (void) |
| Receive datas from the server. Depend of the usage you have to set this method blocant or not (use the setBlocant method).
|
void | sendConfig (double *config, int size) |
| Send a move3d configuration (configPt or double*).
|
std::string & | getServerIp (void) |
| Permit to set the receive function blocant or not.
|
void | setServerIp (std::string &serverIp) |
| Set the server IP address.
|
int & | getPort (void) |
| Get the communication port.
|
void | setPort (int &port) |
| Get the communication port.
|
Static Public Member Functions |
static std::string | convertToString (int i) |
| Convert an int to a std::string.
|
static std::string | convertToString (double d) |
| Convert a double to a std::string.
|
Protected Member Functions |
int & | getSocket (void) |
| Get the socket.
|
void | setSocket (int &socket) |
| Set the socket.
|
struct sockaddr_in & | getSocketAddress (void) |
| Get the socket address.
|
void | setSocketAddress (struct sockaddr_in &si_other) |
| Set the socket address.
|
Detailed Description
Class provinding an UDP client able to communicate over the ethernet with a server identified by its IP address trougth a determined port. To use this class, add the -udp aaa.aaa.aaa.aaa pppp option to the move3d exectutable with a the server ip address and p the port number. After, include the Util-pkg.h. Use then in your functions the global variable "UdpClient * globalUdpClient". To send a message use globalUdpClient->send(std::string("message"));. To receive message use globalUdpClient->receive();. TODO The receive fonction is a blocant one (i.e. the program wait until there is a data comming from the server). To set it non blocant (i.e. the program do not wait. You have to integrate the reveice method into a loop to check if there is a message or not), use the function globalUdpClient->setblocant(false);.
Constructor & Destructor Documentation
UdpClient::UdpClient |
( |
std::string |
serverIp, |
|
|
int |
port |
|
) |
| |
Class constructor. Take the server ip address and the port to establish the connection.
- Parameters:
-
serverIp | The server Ip address |
port | The port number |
Member Function Documentation
static std::string UdpClient::convertToString |
( |
int |
i | ) |
[inline, static] |
Convert an int to a std::string.
- Parameters:
-
- Returns:
- The generated std::string
static std::string UdpClient::convertToString |
( |
double |
d | ) |
[inline, static] |
Convert a double to a std::string.
- Parameters:
-
- Returns:
- The generated std::string
int& UdpClient::getPort |
( |
void |
| ) |
[inline] |
Get the communication port.
- Returns:
- The communication port
std::string& UdpClient::getServerIp |
( |
void |
| ) |
[inline] |
Permit to set the receive function blocant or not.
TODO
- Parameters:
-
block | True to set the process blocant, false otherwise Get the server IP address |
- Returns:
- The server IP address
int& UdpClient::getSocket |
( |
void |
| ) |
[inline, protected] |
Get the socket.
- Returns:
- The socket
struct sockaddr_in& UdpClient::getSocketAddress |
( |
void |
| ) |
[inline, read, protected] |
Get the socket address.
- Returns:
- The socket address
std::string UdpClient::receive |
( |
void |
| ) |
|
Receive datas from the server. Depend of the usage you have to set this method blocant or not (use the setBlocant method).
- Returns:
- The datas received from the server.
void UdpClient::send |
( |
std::string & |
message | ) |
|
Send a text message to the server.
- Parameters:
-
message | The string to send to the server. |
void UdpClient::sendConfig |
( |
double * |
config, |
|
|
int |
size |
|
) |
| |
Send a move3d configuration (configPt or double*).
- Parameters:
-
config | The config to send |
size | The number of items in the config chart |
void UdpClient::setPort |
( |
int & |
port | ) |
[inline] |
Get the communication port.
- Parameters:
-
port | The communication port |
void UdpClient::setServerIp |
( |
std::string & |
serverIp | ) |
[inline] |
Set the server IP address.
- Parameters:
-
serverIp | The server IP address |
void UdpClient::setSocket |
( |
int & |
socket | ) |
[inline, protected] |
Set the socket.
- Parameters:
-
void UdpClient::setSocketAddress |
( |
struct sockaddr_in & |
si_other | ) |
[inline, protected] |
Set the socket address.
- Parameters:
-
si_other | The socket address |
The documentation for this class was generated from the following files:
- /home/slemaign/softs-local/BioMove3D-git/include/UdpClient.h
- /home/slemaign/softs-local/BioMove3D-git/util/UdpClient.cpp