-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (40 loc) · 733 Bytes
/
main.cpp
File metadata and controls
40 lines (40 loc) · 733 Bytes
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
#include"block.h"
#include"Socket_TCP.h"
typedef struct//²»¿¼ÂÇÖ÷»ú×Ö½ÚÐòÎÊÌâ
{
int size;
char *buff;
}buff;
int main()
{
peer client;
Tcp_server ser("127.0.0.1", 43491,0);
client = ser.Accept();
printf("ip:%s,port:%d", inet_ntoa(client.link->sin_addr), ntohs(client.link->sin_port));
buff read;
int fd = client.fd;
while (true)
{
try {
int ret = Reads(fd, &read.size, sizeof(int));
printf("size:%d\n", read.size);
if (ret == 0)
{
throw "cli close";
}
read.buff = new char[read.size];
ret = Reads(fd, read.buff, read.size);
printf("%s\n", read.buff);
if (ret == 0)
{
throw "cli close";
}
delete[]read.buff;
}
catch (char *str)
{
printf("%s\n", str);
break;
}
}
}