#ifndef ZUTIL_NET_SOCKET_IO #define ZUTIL_NET_SOCKET_IO #include #include #include #include #include #include #include #include #include "socketexception.h" using namespace std; //const int MAXHOSTNAME = 200; const int MAX_CONNECTIONS = 5; const int SOCKET_BUFFER = 500; const int MSG_PRIO = 0; // defined by dgame namespace zutil{ class SocketIO{ private: int socket_id; sockaddr_in address; public: SocketIO(); virtual ~SocketIO(); // Server initialization bool create(); bool bind( const int port ); bool listen() const; bool accept( SocketIO& ) const; // Client initialization bool connect( const string host, const int port ); // Data Transimission bool write( const char c ) const; bool write( const string ) const; bool write( const char* buf, const size_t len ) const; char read( ) const; int read( string& ) const; int read( char* buf, const size_t len ) const; void set_non_blocking( const bool ); bool is_valid() const { return socket_id != -1; } }; } #endif