diff options
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 575be2bd..09e9e0a3 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -122,29 +122,29 @@ void printconnection(int connection_id) | |||
122 | 122 | ||
123 | /*( receive packets and send them to the packethandler */ | 123 | /*( receive packets and send them to the packethandler */ |
124 | /*run doLossless_UDP(); */ | 124 | /*run doLossless_UDP(); */ |
125 | void Lossless_UDP() | 125 | //void Lossless_UDP() |
126 | { | 126 | //{ |
127 | /* IP_Port ip_port; | 127 | /* IP_Port ip_port; |
128 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 128 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
129 | uint32_t length; | 129 | uint32_t length; |
130 | while (receivepacket(&ip_port, data, &length) != -1) { | 130 | while (receivepacket(&ip_port, data, &length) != -1) { |
131 | printf("packet with length: %u\n", length); */ | 131 | printf("packet with length: %u\n", length); */ |
132 | /* if(rand() % 3 != 1)//add packet loss | 132 | /* if(rand() % 3 != 1)//add packet loss |
133 | { */ | 133 | { */ |
134 | /* | 134 | /* |
135 | if (LosslessUDP_handlepacket(data, length, ip_port)) | 135 | if (LosslessUDP_handlepacket(data, length, ip_port)) |
136 | printpacket(data, length, ip_port); | 136 | printpacket(data, length, ip_port); |
137 | else | 137 | else |
138 | printf("Received handled packet with length: %u\n", length); //printconnection(0); */ | 138 | printf("Received handled packet with length: %u\n", length); //printconnection(0); */ |
139 | |||
140 | /* } */ | ||
141 | /* }*/ | ||
142 | |||
143 | networking_poll(); | ||
144 | |||
145 | doLossless_UDP(); | ||
146 | 139 | ||
147 | } | 140 | /* } */ |
141 | /* }*/ | ||
142 | |||
143 | //networking_poll(); | ||
144 | |||
145 | //doLossless_UDP(); | ||
146 | |||
147 | //} | ||
148 | 148 | ||
149 | int main(int argc, char *argv[]) | 149 | int main(int argc, char *argv[]) |
150 | { | 150 | { |
@@ -166,25 +166,26 @@ int main(int argc, char *argv[]) | |||
166 | /* bind to ip 0.0.0.0:PORT */ | 166 | /* bind to ip 0.0.0.0:PORT */ |
167 | IP ip; | 167 | IP ip; |
168 | ip.i = 0; | 168 | ip.i = 0; |
169 | init_networking(ip, PORT); | 169 | Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); |
170 | perror("Initialization"); | 170 | perror("Initialization"); |
171 | IP_Port serverip; | 171 | IP_Port serverip; |
172 | serverip.ip.i = inet_addr(argv[1]); | 172 | serverip.ip.i = inet_addr(argv[1]); |
173 | serverip.port = htons(atoi(argv[2])); | 173 | serverip.port = htons(atoi(argv[2])); |
174 | printip(serverip); | 174 | printip(serverip); |
175 | int connection = new_connection(serverip); | 175 | int connection = new_connection(ludp, serverip); |
176 | uint64_t timer = current_time(); | 176 | uint64_t timer = current_time(); |
177 | 177 | ||
178 | while (1) { | 178 | while (1) { |
179 | /* printconnection(connection); */ | 179 | /* printconnection(connection); */ |
180 | Lossless_UDP(); | 180 | networking_poll(ludp->net); |
181 | do_lossless_udp(ludp); | ||
181 | 182 | ||
182 | if (is_connected(connection) == 3) { | 183 | if (is_connected(ludp, connection) == 3) { |
183 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); | 184 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); |
184 | break; | 185 | break; |
185 | } | 186 | } |
186 | 187 | ||
187 | if (is_connected(connection) == 0) { | 188 | if (is_connected(ludp, connection) == 0) { |
188 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); | 189 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); |
189 | return 1; | 190 | return 1; |
190 | } | 191 | } |
@@ -194,25 +195,25 @@ int main(int argc, char *argv[]) | |||
194 | 195 | ||
195 | timer = current_time(); | 196 | timer = current_time(); |
196 | 197 | ||
197 | LosslessUDP_init(); | ||
198 | 198 | ||
199 | /*read first part of file */ | 199 | /*read first part of file */ |
200 | read = fread(buffer, 1, 512, file); | 200 | read = fread(buffer, 1, 512, file); |
201 | 201 | ||
202 | while (1) { | 202 | while (1) { |
203 | /* printconnection(connection); */ | 203 | /* printconnection(connection); */ |
204 | Lossless_UDP(); | 204 | networking_poll(ludp->net); |
205 | do_lossless_udp(ludp); | ||
205 | 206 | ||
206 | if (is_connected(connection) == 3) { | 207 | if (is_connected(ludp, connection) == 3) { |
207 | 208 | ||
208 | if (write_packet(connection, buffer, read)) { | 209 | if (write_packet(ludp, connection, buffer, read)) { |
209 | /* printf("Wrote data.\n"); */ | 210 | /* printf("Wrote data.\n"); */ |
210 | read = fread(buffer, 1, 512, file); | 211 | read = fread(buffer, 1, 512, file); |
211 | 212 | ||
212 | } | 213 | } |
213 | 214 | ||
214 | /* printf("%u\n", sendqueue(connection)); */ | 215 | /* printf("%u\n", sendqueue(connection)); */ |
215 | if (sendqueue(connection) == 0) { | 216 | if (sendqueue(ludp, connection) == 0) { |
216 | if (read == 0) { | 217 | if (read == 0) { |
217 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); | 218 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); |
218 | break; | 219 | break; |