-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.cpp
More file actions
83 lines (66 loc) · 1.8 KB
/
Copy pathclient.cpp
File metadata and controls
83 lines (66 loc) · 1.8 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
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
#include "UdpClientSocket.h"
#include "TcpClientSocket.h"
#define UDP_CLIENT_PORT 6500
#define TCP_CLIENT_PORT 6600
#define UDP_SERV_PORT 7718
#define TCP_SERV_PORT 7799
int main()
{
char* message;
char IP[100], buf[BUFSIZE], file_name[100];
int select;
strcpy(IP, "127.0.0.1");
UdpClientSocket udp(UDP_CLIENT_PORT, IP, UDP_SERV_PORT);
TcpClientSocket tcp(TCP_CLIENT_PORT, IP, TCP_SERV_PORT);
udp.createSocket();
tcp.createSocket();
tcp.connectSocket();
Sleep(1000);
strcpy(buf, "I want to download a file");
udp.sendMessage(buf);
// receive data list
message = udp.receiveMessage();
// select data
while(true)
{
printf("%s\n", message);
printf("Please select a number : ");
scanf("%d", &select);
if(select == 1 || select == 2 || select == 3) break;
else printf("Invalid number\n\n");
}
// send select number
sprintf(buf, "%d", select);
udp.sendMessage(buf);
//receive file list size
strcpy(buf, udp.receiveMessage());
int size = atoi(buf);
//receive file
for(int i=0; i<size; i++)
{
// receive file size
strcpy(buf, udp.receiveMessage());
int file_size = atoi(buf);
if(file_size <= 1024 * 64)
{
char* file_name = udp.receiveMessage();
udp.receiveFile(file_name);
}
else
{
char* file_name = tcp.receiveMessage();
tcp.receiveFile(file_name);
}
}
vector<string> fail_file_list = tcp.getCorruptedFileList();
size = fail_file_list.size();
printf("\n----------download fail file----------\n");
int cnt = 1;
for(int i=0; i<size; i++)
printf("%d. %s\n", cnt++, (char*)fail_file_list[i].c_str());
fail_file_list = udp.getCorruptedFileList();
size = fail_file_list.size();
for(int i=0; i<size; i++)
printf("%d. %s\n", cnt++, (char*)fail_file_list[i].c_str());
return 0;
}