diff options
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 8f23528c..c1eaa69d 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -44,13 +44,13 @@ | |||
44 | 44 | ||
45 | #define PORT 33446 | 45 | #define PORT 33446 |
46 | 46 | ||
47 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | 47 | void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) |
48 | { | 48 | { |
49 | uint32_t i; | 49 | uint32_t i; |
50 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 50 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
51 | printf("--------------------BEGIN-----------------------------\n"); | 51 | printf("--------------------BEGIN-----------------------------\n"); |
52 | for(i = 0; i < length; i++) { | 52 | for (i = 0; i < length; i++) { |
53 | if(data[i] < 16) | 53 | if (data[i] < 16) |
54 | printf("0"); | 54 | printf("0"); |
55 | printf("%hhX",data[i]); | 55 | printf("%hhX",data[i]); |
56 | } | 56 | } |
@@ -59,7 +59,7 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | |||
59 | 59 | ||
60 | void printip(IP_Port ip_port) | 60 | void printip(IP_Port ip_port) |
61 | { | 61 | { |
62 | 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)); | 62 | 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)); |
63 | } | 63 | } |
64 | /* | 64 | /* |
65 | void printpackets(Data test) | 65 | void printpackets(Data test) |
@@ -123,16 +123,15 @@ void Lossless_UDP() | |||
123 | IP_Port ip_port; | 123 | IP_Port ip_port; |
124 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 124 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
125 | uint32_t length; | 125 | uint32_t length; |
126 | while(receivepacket(&ip_port, data, &length) != -1) { | 126 | while (receivepacket(&ip_port, data, &length) != -1) { |
127 | printf("packet with length: %u\n", length); | 127 | printf("packet with length: %u\n", length); |
128 | /* if(rand() % 3 != 1)//add packet loss | 128 | /* if(rand() % 3 != 1)//add packet loss |
129 | { */ | 129 | { */ |
130 | if(LosslessUDP_handlepacket(data, length, ip_port)) { | 130 | if (LosslessUDP_handlepacket(data, length, ip_port)) |
131 | printpacket(data, length, ip_port); | 131 | printpacket(data, length, ip_port); |
132 | } else { | 132 | else |
133 | //printconnection(0); | 133 | printf("Received handled packet with length: %u\n", length); //printconnection(0); |
134 | printf("Received handled packet with length: %u\n", length); | 134 | |
135 | } | ||
136 | /* } */ | 135 | /* } */ |
137 | } | 136 | } |
138 | 137 | ||
@@ -151,7 +150,8 @@ int main(int argc, char *argv[]) | |||
151 | int read; | 150 | int read; |
152 | 151 | ||
153 | FILE *file = fopen(argv[3], "rb"); | 152 | FILE *file = fopen(argv[3], "rb"); |
154 | if ( file==NULL ){return 1;} | 153 | if (file == NULL) |
154 | return 1; | ||
155 | 155 | ||
156 | 156 | ||
157 | /* initialize networking */ | 157 | /* initialize networking */ |
@@ -166,14 +166,14 @@ int main(int argc, char *argv[]) | |||
166 | printip(serverip); | 166 | printip(serverip); |
167 | int connection = new_connection(serverip); | 167 | int connection = new_connection(serverip); |
168 | uint64_t timer = current_time(); | 168 | uint64_t timer = current_time(); |
169 | while(1) { | 169 | while (1) { |
170 | /* printconnection(connection); */ | 170 | /* printconnection(connection); */ |
171 | Lossless_UDP(); | 171 | Lossless_UDP(); |
172 | if(is_connected(connection) == 3) { | 172 | if (is_connected(connection) == 3) { |
173 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); | 173 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); |
174 | break; | 174 | break; |
175 | } | 175 | } |
176 | if(is_connected(connection) == 0) { | 176 | if (is_connected(connection) == 0) { |
177 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); | 177 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); |
178 | return 1; | 178 | return 1; |
179 | } | 179 | } |
@@ -185,19 +185,19 @@ int main(int argc, char *argv[]) | |||
185 | /*read first part of file */ | 185 | /*read first part of file */ |
186 | read = fread(buffer, 1, 512, file); | 186 | read = fread(buffer, 1, 512, file); |
187 | 187 | ||
188 | while(1) { | 188 | while (1) { |
189 | /* printconnection(connection); */ | 189 | /* printconnection(connection); */ |
190 | Lossless_UDP(); | 190 | Lossless_UDP(); |
191 | if(is_connected(connection) == 3) { | 191 | if (is_connected(connection) == 3) { |
192 | 192 | ||
193 | if(write_packet(connection, buffer, read)) { | 193 | if (write_packet(connection, buffer, read)) { |
194 | /* printf("Wrote data.\n"); */ | 194 | /* printf("Wrote data.\n"); */ |
195 | read = fread(buffer, 1, 512, file); | 195 | read = fread(buffer, 1, 512, file); |
196 | 196 | ||
197 | } | 197 | } |
198 | /* printf("%u\n", sendqueue(connection)); */ | 198 | /* printf("%u\n", sendqueue(connection)); */ |
199 | if(sendqueue(connection) == 0) { | 199 | if (sendqueue(connection) == 0) { |
200 | if(read == 0) { | 200 | if (read == 0) { |
201 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); | 201 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); |
202 | break; | 202 | break; |
203 | } | 203 | } |