libmove3d  3.13.0
Public Member Functions | Static Public Member Functions | Protected Member Functions
UdpClient Class Reference

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:
serverIpThe server Ip address
portThe port number

Member Function Documentation

static std::string UdpClient::convertToString ( int  i) [inline, static]

Convert an int to a std::string.

Parameters:
iThe int to convert
Returns:
The generated std::string
static std::string UdpClient::convertToString ( double  d) [inline, static]

Convert a double to a std::string.

Parameters:
dThe double to convert
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:
blockTrue 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:
messageThe string to send to the server.
void UdpClient::sendConfig ( double *  config,
int  size 
)

Send a move3d configuration (configPt or double*).

Parameters:
configThe config to send
sizeThe number of items in the config chart
void UdpClient::setPort ( int &  port) [inline]

Get the communication port.

Parameters:
portThe communication port
void UdpClient::setServerIp ( std::string &  serverIp) [inline]

Set the server IP address.

Parameters:
serverIpThe server IP address
void UdpClient::setSocket ( int &  socket) [inline, protected]

Set the socket.

Parameters:
socketThe socket
void UdpClient::setSocketAddress ( struct sockaddr_in &  si_other) [inline, protected]

Set the socket address.

Parameters:
si_otherThe socket address

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines