Share Pastebin
Guest
Public paste!

Socket.h

By: a guest | Mar 18th, 2010 | Syntax: C++ | Size: 0.73 KB | Hits: 42 | Expires: Never
Copy text to clipboard
  1. /* Socket.h */
  2.  
  3. #ifndef Socket_class
  4. #define Socket_class
  5.  
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <netdb.h>
  10. #include <unistd.h>
  11. #include <string>
  12. #include <arpa/inet.h>
  13.  
  14. const int MAXHOSTNAME = 200;
  15. const int MAXCONNECTIONS = 5;
  16. const int MAXRECV = 500;
  17.  
  18. class Socket
  19. {
  20.  public:
  21.   Socket(const std::string server,const std::string port);
  22.   ~Socket();
  23.  
  24.   bool get_address();
  25.   bool connect();
  26.   bool is_valid() const { return m_sock != -1; }
  27.   const Socket& operator >> (std::string&) const;
  28.   const Socket& operator << (const std::string&) const;
  29.  
  30.  private:
  31.   const std::string server;
  32.   const std::string port;
  33.  
  34.   int m_sock;
  35.   struct addrinfo hints, *servinfo;
  36.  
  37. };
  38. #endif