forked from codercheng/CodeSnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.cpp
More file actions
57 lines (43 loc) · 1.11 KB
/
Server.cpp
File metadata and controls
57 lines (43 loc) · 1.11 KB
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
//#include <ev.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "EasySock.h"
int listenFd;
int main()
{
CreateAndBind(listenFd);
int conn_fd;
struct sockaddr_in client_addr;
socklen_t len = sizeof(client_addr);
conn_fd = accept(listenFd, (struct sockaddr *)&client_addr, &len);
if(conn_fd > 0){
printf("got connection from ip:%s, port:%d\n",
inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
SockRecv sockRecv;
sockRecv.SyncRecv(conn_fd);
int iValue;
char cValue;
long long int lValue;
bool bValue;
char cValue2;
sockRecv.GetInt32(iValue);
sockRecv.GetChar(cValue);
sockRecv.GetInt64(lValue);
sockRecv.GetBool(bValue);
sockRecv.GetChar(cValue2);
printf("[%d:%c:%lld:%d:%c]\n", iValue, cValue, lValue, bValue, cValue2);
}
else if(conn_fd < 0){
printf("connection error:%s ...\n", strerror(errno));
}
close(conn_fd);
close(listenFd);
printf("server exit successfully\n");
return 0;
}
// g++ -g -Wall EasySock.cpp EasyScm.cpp -o Server