00001 /* 00002 Estimation and computation of a multivariate multidimensional polynomial. 00003 00004 Copyright (C) 2010 - 2014 Christoph Haenisch 00005 00006 Chair of Medical Engineering (mediTEC) 00007 RWTH Aachen University 00008 Pauwelsstr. 20 00009 52074 Aachen 00010 Germany 00011 00012 See license.txt for more information. 00013 00014 Version 0.1.1 (2014-07-05) 00015 */ 00016 00022 #ifndef CLIENT_SERVER_HPP_4749718748 00023 #define CLIENT_SERVER_HPP_4749718748 00024 00025 00026 #include <stdexcept> 00027 #include <utility> 00028 00029 00030 namespace TRTK 00031 { 00032 00033 00036 class NetworkError : public std::runtime_error 00037 { 00038 public: 00039 explicit NetworkError(const std::string & what); 00040 }; 00041 00042 00045 class ConnectionClosed : public NetworkError 00046 { 00047 public: 00048 explicit ConnectionClosed(const std::string & what); 00049 }; 00050 00051 00065 class Client 00066 { 00067 public: 00068 Client(); 00069 virtual ~Client(); 00070 00071 void connect(std::string host, short port); 00072 void disconnect(); 00073 std::pair<char *, size_t> request(const char * data, size_t size); 00074 00075 private: 00076 void receiveData(char * & data, size_t & size); 00077 void sendData(const char * data, size_t size); 00078 00079 int socket_fd; 00080 bool connected; 00081 }; 00082 00083 00214 class Server 00215 { 00216 public: 00217 Server(); 00218 virtual ~Server(); 00219 00220 void startServer(short port); 00221 void stopServer(); 00222 00223 virtual std::pair<char *, size_t> handleRequest(const char * received_data, size_t length) = 0; 00224 00225 void closeConnection(); 00226 00227 private: 00228 void receiveData(char * & data, size_t & size); 00229 void sendData(const char * data, size_t size); 00230 00231 int client_fd; 00232 bool close_connection; 00233 volatile bool stop_server; 00234 }; 00235 00236 00237 } // namespace TRTK 00238 00239 00240 #endif // CLIENT_SERVER_HPP_4749718748
Documentation generated by Doxygen