-
Notifications
You must be signed in to change notification settings - Fork 0
/
Socket.h
84 lines (71 loc) · 1.56 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef SOCKET_H
#define SOCKET_H
#include <string>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
class Socket
{
private:
int m_socketNum;
// The ip version, either AF_INET or AF_INET6.
int m_ipV;
protected:
/**
* Set the Ip version.
*/
void setIpV(const int ipV);
/**
* Get the Ip version
*/
int getIpV() const;
/**
* Set the socket number.
*/
void setSocketNum(const int socket);
public:
// Buffer size
static const int BUFFER_SIZE = 16384;
// String to represent ENTER
static constexpr const char *ENTER = "ENTER";
/**
* Binding the socket IP to the socket port.
*/
void bindSocket(const char *sourceIp, const int sourcePort);
/**
* Close the socket.
*/
void closeSocket();
/**
* Initialize the socket.
*/
virtual void init(const int ipV) = 0;
/**
* Connect to a socket.
*/
virtual void connectSocket(const char *destIp, const int destPort) = 0;
/**
*Listen for incoming sockets.
*/
virtual void listenSocket() = 0;
/**
* Accept an incoming socket.
*/
virtual int acceptSocket() = 0;
/**
* Sending a messege to another socket.
*/
virtual void sendSocket(std::string message) = 0;
/**
* Receiving a messege from another socket.
*/
virtual void recvSocket(char *buffer, int len) = 0;
/**
* Get the socket number.
*/
int getSocketNum() const;
};
#endif