diff options
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 07ab319b..8f23528c 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -42,7 +42,6 @@ | |||
42 | 42 | ||
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | |||
46 | #define PORT 33446 | 45 | #define PORT 33446 |
47 | 46 | ||
48 | 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) |
@@ -50,8 +49,7 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | |||
50 | uint32_t i; | 49 | uint32_t i; |
51 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 50 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
52 | printf("--------------------BEGIN-----------------------------\n"); | 51 | printf("--------------------BEGIN-----------------------------\n"); |
53 | for(i = 0; i < length; i++) | 52 | for(i = 0; i < length; i++) { |
54 | { | ||
55 | if(data[i] < 16) | 53 | if(data[i] < 16) |
56 | printf("0"); | 54 | printf("0"); |
57 | printf("%hhX",data[i]); | 55 | printf("%hhX",data[i]); |
@@ -117,39 +115,34 @@ void printconnection(int connection_id) | |||
117 | 115 | ||
118 | } | 116 | } |
119 | */ | 117 | */ |
120 | //recieve packets and send them to the packethandler | 118 | |
121 | //run doLossless_UDP(); | 119 | /*( recieve packets and send them to the packethandler */ |
120 | /*run doLossless_UDP(); */ | ||
122 | void Lossless_UDP() | 121 | void Lossless_UDP() |
123 | { | 122 | { |
124 | IP_Port ip_port; | 123 | IP_Port ip_port; |
125 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 124 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
126 | uint32_t length; | 125 | uint32_t length; |
127 | while(receivepacket(&ip_port, data, &length) != -1) | 126 | while(receivepacket(&ip_port, data, &length) != -1) { |
128 | { | ||
129 | printf("packet with length: %u\n", length); | 127 | printf("packet with length: %u\n", length); |
130 | //if(rand() % 3 != 1)//add packet loss | 128 | /* if(rand() % 3 != 1)//add packet loss |
131 | // { | 129 | { */ |
132 | if(LosslessUDP_handlepacket(data, length, ip_port)) | 130 | if(LosslessUDP_handlepacket(data, length, ip_port)) { |
133 | { | ||
134 | printpacket(data, length, ip_port); | 131 | printpacket(data, length, ip_port); |
135 | } | 132 | } else { |
136 | else | ||
137 | { | ||
138 | //printconnection(0); | 133 | //printconnection(0); |
139 | printf("Received handled packet with length: %u\n", length); | 134 | printf("Received handled packet with length: %u\n", length); |
140 | } | 135 | } |
141 | // } | 136 | /* } */ |
142 | } | 137 | } |
143 | 138 | ||
144 | doLossless_UDP(); | 139 | doLossless_UDP(); |
145 | 140 | ||
146 | } | 141 | } |
147 | 142 | ||
148 | |||
149 | int main(int argc, char *argv[]) | 143 | int main(int argc, char *argv[]) |
150 | { | 144 | { |
151 | if (argc < 4) | 145 | if (argc < 4) { |
152 | { | ||
153 | printf("usage: %s ip port filename\n", argv[0]); | 146 | printf("usage: %s ip port filename\n", argv[0]); |
154 | exit(0); | 147 | exit(0); |
155 | } | 148 | } |
@@ -161,8 +154,8 @@ int main(int argc, char *argv[]) | |||
161 | if ( file==NULL ){return 1;} | 154 | if ( file==NULL ){return 1;} |
162 | 155 | ||
163 | 156 | ||
164 | //initialize networking | 157 | /* initialize networking */ |
165 | //bind to ip 0.0.0.0:PORT | 158 | /* bind to ip 0.0.0.0:PORT */ |
166 | IP ip; | 159 | IP ip; |
167 | ip.i = 0; | 160 | ip.i = 0; |
168 | init_networking(ip, PORT); | 161 | init_networking(ip, PORT); |
@@ -173,17 +166,14 @@ int main(int argc, char *argv[]) | |||
173 | printip(serverip); | 166 | printip(serverip); |
174 | int connection = new_connection(serverip); | 167 | int connection = new_connection(serverip); |
175 | uint64_t timer = current_time(); | 168 | uint64_t timer = current_time(); |
176 | while(1) | 169 | while(1) { |
177 | { | 170 | /* printconnection(connection); */ |
178 | // printconnection(connection); | ||
179 | Lossless_UDP(); | 171 | Lossless_UDP(); |
180 | if(is_connected(connection) == 3) | 172 | if(is_connected(connection) == 3) { |
181 | { | ||
182 | 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)); |
183 | break; | 174 | break; |
184 | } | 175 | } |
185 | if(is_connected(connection) == 0) | 176 | if(is_connected(connection) == 0) { |
186 | { | ||
187 | 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)); |
188 | return 1; | 178 | return 1; |
189 | } | 179 | } |
@@ -192,38 +182,32 @@ int main(int argc, char *argv[]) | |||
192 | timer = current_time(); | 182 | timer = current_time(); |
193 | 183 | ||
194 | 184 | ||
195 | //read first part of file | 185 | /*read first part of file */ |
196 | read = fread(buffer, 1, 512, file); | 186 | read = fread(buffer, 1, 512, file); |
197 | 187 | ||
198 | while(1) | 188 | while(1) { |
199 | { | 189 | /* printconnection(connection); */ |
200 | //printconnection(connection); | ||
201 | Lossless_UDP(); | 190 | Lossless_UDP(); |
202 | if(is_connected(connection) == 3) | 191 | if(is_connected(connection) == 3) { |
203 | { | ||
204 | 192 | ||
205 | if(write_packet(connection, buffer, read)) | 193 | if(write_packet(connection, buffer, read)) { |
206 | { | 194 | /* printf("Wrote data.\n"); */ |
207 | //printf("Wrote data.\n"); | ||
208 | read = fread(buffer, 1, 512, file); | 195 | read = fread(buffer, 1, 512, file); |
209 | 196 | ||
210 | } | 197 | } |
211 | //printf("%u\n", sendqueue(connection)); | 198 | /* printf("%u\n", sendqueue(connection)); */ |
212 | if(sendqueue(connection) == 0) | 199 | if(sendqueue(connection) == 0) { |
213 | { | 200 | if(read == 0) { |
214 | if(read == 0) | ||
215 | { | ||
216 | 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)); |
217 | break; | 202 | break; |
218 | } | 203 | } |
219 | } | 204 | } |
220 | } | 205 | } |
221 | else | 206 | else { |
222 | { | ||
223 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); | 207 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); |
224 | return 0; | 208 | return 0; |
225 | } | 209 | } |
226 | //c_sleep(1); | 210 | /* c_sleep(1); */ |
227 | } | 211 | } |
228 | 212 | ||
229 | return 0; | 213 | return 0; |