forked from liranbg/jceConnection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.h
57 lines (43 loc) · 1.06 KB
/
socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef Socket_H
#define Socket_H
#define FAIL -1
#define socketTimeOut 4
//sock headers
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <iostream>
#include <string.h>
const int MAXHOSTNAME = 200;
const int MAXCONNECTIONS = 5;
const int MAXRECV = 10000;
class Socket
{
protected:
Socket();
virtual ~Socket();
// Server initialization
bool create();
bool bind ( const int port ); //binding port
bool listen() const;
bool accept ( Socket& ) const;
// Client initialization
bool connect ( const std::string host, const int port );
// Data Transimission
virtual bool send ( const std::string ) const;
virtual bool recv ( ) const;
void close();
void set_non_blocking ( const bool );
bool is_valid() const { return (m_sock != FAIL); }
int getSocket() { if (is_valid()) return m_sock; //else
return FAIL; }
private:
int m_sock;
sockaddr_in m_addr;
};
#endif