diff options
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 20fae86f..5790ad3b 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* Lossless_UDP testclient | 1 | /* Lossless_UDP testclient |
2 | * A program that connects and sends a file using our lossless UDP algorithm. | 2 | * A program that connects and sends a file using our lossless UDP algorithm. |
3 | * NOTE: this program simulates a 33% packet loss. | ||
3 | * | 4 | * |
4 | * Best used in combination with Lossless_UDP_testserver | 5 | * Best used in combination with Lossless_UDP_testserver |
5 | * | 6 | * |
@@ -44,7 +45,7 @@ void printip(IP_Port ip_port) | |||
44 | { | 45 | { |
45 | printf("\nIP: %u.%u.%u.%u Port: %u",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); | 46 | printf("\nIP: %u.%u.%u.%u Port: %u",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); |
46 | } | 47 | } |
47 | 48 | /* | |
48 | void printpackets(Data test) | 49 | void printpackets(Data test) |
49 | { | 50 | { |
50 | int i; | 51 | int i; |
@@ -80,14 +81,14 @@ void printconnection(int connection_id) | |||
80 | } | 81 | } |
81 | Data sendbuffer[MAX_QUEUE_NUM]; | 82 | Data sendbuffer[MAX_QUEUE_NUM]; |
82 | Data recvbuffer[MAX_QUEUE_NUM]; | 83 | Data recvbuffer[MAX_QUEUE_NUM]; |
83 | printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n", | 84 | printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n", |
84 | connections[connection_id].recv_packetnum, | 85 | connections[connection_id].recv_packetnum, |
85 | connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum, | 86 | connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum, |
86 | connections[connection_id].successful_sent, | 87 | connections[connection_id].successful_sent, |
87 | connections[connection_id].successful_read); | 88 | connections[connection_id].successful_read); |
88 | 89 | ||
89 | printf("req packets: \n"); | 90 | printf("req packets: \n"); |
90 | for(i = 0; i < MAX_PACKET_NUM; i++) | 91 | for(i = 0; i < BUFFER_PACKET_NUM; i++) |
91 | { | 92 | { |
92 | printf(" %u ", connections[connection_id].req_packets[i]); | 93 | printf(" %u ", connections[connection_id].req_packets[i]); |
93 | } | 94 | } |
@@ -97,7 +98,7 @@ void printconnection(int connection_id) | |||
97 | printf("--------------------END---------------------\n"); | 98 | printf("--------------------END---------------------\n"); |
98 | 99 | ||
99 | } | 100 | } |
100 | 101 | */ | |
101 | //recieve packets and send them to the packethandler | 102 | //recieve packets and send them to the packethandler |
102 | //run doLossless_UDP(); | 103 | //run doLossless_UDP(); |
103 | void Lossless_UDP() | 104 | void Lossless_UDP() |
@@ -107,18 +108,19 @@ void Lossless_UDP() | |||
107 | uint32_t length; | 108 | uint32_t length; |
108 | while(recievepacket(&ip_port, data, &length) != -1) | 109 | while(recievepacket(&ip_port, data, &length) != -1) |
109 | { | 110 | { |
111 | printf("packet with length: %u\n", length); | ||
110 | if(rand() % 3 != 1)//add packet loss | 112 | if(rand() % 3 != 1)//add packet loss |
111 | 113 | { | |
112 | if(LosslessUDP_handlepacket(data, length, ip_port)) | 114 | if(LosslessUDP_handlepacket(data, length, ip_port)) |
113 | { | 115 | { |
114 | printpacket(data, length, ip_port); | 116 | printpacket(data, length, ip_port); |
115 | } | 117 | } |
116 | else | 118 | else |
117 | { | 119 | { |
118 | //printconnection(0); | 120 | //printconnection(0); |
119 | printf("Received handled packet with length: %u\n", length); | 121 | printf("Received handled packet with length: %u\n", length); |
122 | } | ||
120 | } | 123 | } |
121 | |||
122 | } | 124 | } |
123 | 125 | ||
124 | doLossless_UDP(); | 126 | doLossless_UDP(); |
@@ -155,6 +157,7 @@ int main(int argc, char *argv[]) | |||
155 | uint64_t timer = current_time(); | 157 | uint64_t timer = current_time(); |
156 | while(1) | 158 | while(1) |
157 | { | 159 | { |
160 | // printconnection(connection); | ||
158 | Lossless_UDP(); | 161 | Lossless_UDP(); |
159 | if(is_connected(connection) == 3) | 162 | if(is_connected(connection) == 3) |
160 | { | 163 | { |
@@ -166,27 +169,28 @@ int main(int argc, char *argv[]) | |||
166 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); | 169 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); |
167 | return 1; | 170 | return 1; |
168 | } | 171 | } |
169 | c_sleep(100); | 172 | c_sleep(1); |
170 | } | 173 | } |
171 | timer = current_time(); | 174 | timer = current_time(); |
172 | 175 | ||
173 | 176 | ||
174 | //read first part of file | 177 | //read first part of file |
175 | read = fread(buffer, 1, 1, file); | 178 | read = fread(buffer, 1, 128, file); |
176 | 179 | ||
177 | while(1) | 180 | while(1) |
178 | { | 181 | { |
179 | //printconnection(connection); | 182 | //printconnection(connection); |
180 | Lossless_UDP(); | 183 | Lossless_UDP(); |
181 | |||
182 | if(is_connected(connection) == 3) | 184 | if(is_connected(connection) == 3) |
183 | { | 185 | { |
184 | 186 | ||
185 | if(write_packet(connection, buffer, read)) | 187 | if(write_packet(connection, buffer, read)) |
186 | { | 188 | { |
187 | //printf("Wrote data.\n"); | 189 | //printf("Wrote data.\n"); |
188 | read = fread(buffer, 1, 1, file); | 190 | read = fread(buffer, 1, 128, file); |
191 | |||
189 | } | 192 | } |
193 | //printf("%u\n", sendqueue(connection)); | ||
190 | if(sendqueue(connection) == 0) | 194 | if(sendqueue(connection) == 0) |
191 | { | 195 | { |
192 | if(read == 0) | 196 | if(read == 0) |
@@ -201,7 +205,7 @@ int main(int argc, char *argv[]) | |||
201 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); | 205 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); |
202 | return 0; | 206 | return 0; |
203 | } | 207 | } |
204 | c_sleep(50); | 208 | c_sleep(1); |
205 | } | 209 | } |
206 | 210 | ||
207 | return 0; | 211 | return 0; |