libmove3d  3.13.0
/home/slemaign/softs-local/BioMove3D-git/include/UdpClient.h
00001 #ifndef __UDPCLIENT_H__
00002 #define __UDPCLIENT_H__
00003 
00004 #include <arpa/inet.h>
00005 #include <netinet/in.h>
00006 #include <iostream>
00007 #include <sstream>
00008 
00014 class UdpClient {
00015 public:
00016   //Constructors and destructors
00022   UdpClient(std::string serverIp, int port);
00026   virtual ~UdpClient();
00027   //functions
00028     //send
00033   void send(std::string& message);
00034     //receive
00039   std::string receive(void);
00041 
00046   void sendConfig(double * config, int size);
00048   //setters and getters
00053 //   void setBlocant(bool block);
00058   inline std::string& getServerIp(void){return _serverIp;}
00063   inline void setServerIp(std::string& serverIp){_serverIp = serverIp;}
00068   inline int& getPort(void){ return _port;}
00073   inline void setPort(int& port){_port = port;}
00074 protected:
00075   //setters and getters
00080   inline int& getSocket(void){return _socket;}
00085   inline void setSocket(int& socket){_socket = socket;}
00090   inline struct sockaddr_in& getSocketAddress(void){return _si_other;}
00095   inline void setSocketAddress(struct sockaddr_in& si_other){_si_other = si_other;}
00096 private:
00100   std::string _serverIp;
00104   int _port;
00108   int _socket;
00112   struct sockaddr_in _si_other;
00113 //static members
00114 public:
00120   static std::string convertToString(int i){
00121     std::string s;
00122     std::stringstream out;
00123     out << i;
00124     s = out.str();
00125     return s;
00126   }
00132   static std::string convertToString(double d){
00133     std::string s;
00134     std::stringstream out;
00135     out << d;
00136     s = out.str();
00137     return s;
00138   }
00139 };
00140 
00141 extern UdpClient* globalUdpClient;
00142 
00143 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines