Line | |
---|
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 | #include <iostream> |
---|
15 | #include "stdio.h" |
---|
16 | |
---|
17 | |
---|
18 | const int MAXHOSTNAME = 1000; |
---|
19 | const int MAXCONNECTIONS = 5; |
---|
20 | const int MAXRECV = 5000; |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | class socketdef |
---|
25 | { |
---|
26 | public: |
---|
27 | socketdef(); |
---|
28 | virtual ~socketdef(); |
---|
29 | |
---|
30 | |
---|
31 | // Server initialization |
---|
32 | bool create(); |
---|
33 | bool bind ( const int port ); |
---|
34 | bool listen() const; |
---|
35 | bool accept ( socketdef& ) const; |
---|
36 | |
---|
37 | // Client initialization |
---|
38 | bool connect ( const std::string host, const int port ); |
---|
39 | |
---|
40 | // Data Transimission |
---|
41 | bool send ( const std::string ) const; |
---|
42 | int recv ( std::string& ) const; |
---|
43 | |
---|
44 | |
---|
45 | void set_non_blocking ( const bool ); |
---|
46 | |
---|
47 | bool is_valid() const { return m_sock != -1; } |
---|
48 | |
---|
49 | bool shutdown(); |
---|
50 | |
---|
51 | private: |
---|
52 | |
---|
53 | int m_sock; |
---|
54 | sockaddr_in m_addr; |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | }; |
---|
60 | |
---|
61 | |
---|
62 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.