// // Definitions of socket classes for boost // #include #include #ifndef boost_sockets #define boost_sockets // // Creates a client socket // class client_socket : private socket { public: client_socket ( std::string host, int port ); virtual ~client_socket(){}; const client_socket& operator << ( const std::string& ) const; const client_socket& operator >> ( std::string& ) const; const client_socket& operator << ( const marshallable& ) const; const client_socket& operator >> ( marshallable& ) const; }; // // Creates a server socket // class server_socket : private socket { public: server_socket ( int port ); server_socket (){}; virtual ~server_socket(); const server_socket& operator << ( const std::string& ) const; const server_socket& operator >> ( std::string& ) const; const server_socket& operator << ( const marshallable& ) const; const server_socket& operator >> ( marshallable& ) const; void accept ( server_socket& ); }; // // Inherit from marshallable and implement // marshal and unmarshal to allow your class // to be sent across a socket. // class marshallable { public: marshallable(){}; ~marshallable(){}; virtual void marshal ( std::ostringstream& ); virtual void unmarshal ( std::istringstream& ); }; // // exception class // class socket_exception { public: socket_exception ( std;:string ); ~socket_exception(); }; // // Most of the implementation is in here. We // can have a different class for each platform. // class socket { public: socket(); virtual ~socket(); // Server initialization bool create(); bool bind ( const int port ); bool listen() const; bool accept ( Socket& ) const; // Client initialization bool connect ( const std::string host, const int port ); // Data Transimission bool send ( const std::string ) const; int recv ( std::string& ) const; bool is_valid() const { return m_sock != -1; } private: int m_sock; sockaddr_in m_addr; }; #endif