-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
48 lines (41 loc) · 863 Bytes
/
server.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
#ifndef SERVER_H_
#define SERVER_H_
#include <iostream>
#include <cstring>
#include <stdexcept>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define BUFFER_SIZE 1024
#define PORT_NUM 5001
#define BACKLOG 5
class TCPServer
{
private:
int sockfd;
public:
TCPServer();
~TCPServer()
{
close(sockfd);
}
int acceptClient(sockaddr_in &clientAddr);
int getServerSocketFd() const;
};
class ClientHandler
{
private:
int newsockfd;
sockaddr_in clientAddr;
int clientNum;
public:
ClientHandler(int fd, sockaddr_in addr, int num) : newsockfd(fd), clientAddr(addr), clientNum(num) {}
~ClientHandler()
{
close(newsockfd);
}
void handleClient();
};
#endif