Rueba  1.0
Refectory Access System
Socket.h
1 // Definition of the Socket class
2 
3 #ifndef Socket_class
4 #define Socket_class
5 
6 
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <netdb.h>
11 #include <unistd.h>
12 #include <string>
13 #include <arpa/inet.h>
14 
15 
16 const int MAXHOSTNAME = 200;
17 const int MAXCONNECTIONS = 5;
18 const int MAXRECV = 500;
19 
20 class Socket
21 {
22  public:
23  Socket();
24  virtual ~Socket();
25 
26  // Server initialization
27  bool create();
28  bool bind ( const int port );
29  bool listen() const;
30  bool accept ( Socket& ) const;
31 
32  // Client initialization
33  bool connect ( const std::string host, const int port );
34 
35  // Data Transimission
36  bool send ( const std::string ) const;
37  int recv ( std::string& ) const;
38 
39 
40  void set_non_blocking ( const bool );
41 
42  bool is_valid() const { return m_sock != -1; }
43 
44  private:
45 
46  int m_sock;
47  sockaddr_in m_addr;
48 
49 
50 };
51 
52 
53 #endif
Definition: Socket.h:20