From fd44c68801205eeece6495a641db50467ee4ece5 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 28 Jun 2013 09:15:19 -0400 Subject: Couple fixes. --- testing/Lossless_UDP_testclient.c | 44 +++++++++++++++++++++++---------------- testing/Lossless_UDP_testserver.c | 43 +++++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 35 deletions(-) (limited to 'testing') diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index bd4b1e23..d092125b 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c @@ -3,7 +3,7 @@ * * Best used in combination with Lossless_UDP_testserver * - * Compile with: gcc -O2 -Wall -o test ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testclient.c + * Compile with: gcc -O2 -Wall -o testclient ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testclient.c * * Command line arguments are the ip and port to cennect and send the file to. * EX: ./test 127.0.0.1 33445 filename.txt @@ -40,6 +40,29 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port) printf("\n--------------------END-----------------------------\n\n\n"); } +//recieve packets and send them to the packethandler +//run doLossless_UDP(); +void Lossless_UDP() +{ + IP_Port ip_port; + char data[MAX_UDP_PACKET_SIZE]; + uint32_t length; + while(recievepacket(&ip_port, data, &length) != -1) + { + if(LosslessUDP_handlepacket(data, length, ip_port)) + { + printpacket(data, length, ip_port); + } + else + { + printf("Received handled packet with length: %u\n", length); + } + } + + doLossless_UDP(); + +} + int main(int argc, char *argv[]) { @@ -68,7 +91,7 @@ int main(int argc, char *argv[]) uint64_t timer = current_time(); while(1) { - + Lossless_UDP(); if(is_connected(connection) == 3) { printf("Connecting took: %llu us", (unsigned long long)(current_time() - timer)); @@ -83,28 +106,13 @@ int main(int argc, char *argv[]) } timer = current_time(); - IP_Port ip_port; - char data[MAX_UDP_PACKET_SIZE]; - uint32_t length; //read first part of file read = fread(buffer, 1, 128, file); while(1) { - while(recievepacket(&ip_port, data, &length) != -1) - { - if(LosslessUDP_handlepacket(data, length, ip_port)) - { - printpacket(data, length, ip_port); - } - else - { - printf("Received handled packet with length: %u\n", length); - } - } - - doLossless_UDP(); + Lossless_UDP(); if(is_connected(connection) == 1) { diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index c898d887..5ae35574 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c @@ -3,7 +3,7 @@ * * Best used in combination with Lossless_UDP_testclient * - * Compile with: gcc -O2 -Wall -o test ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testserver.c + * Compile with: gcc -O2 -Wall -o testserver ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testserver.c * * Command line argument is the name of the file to save what we recieve to. * EX: ./test filename1.txt @@ -41,6 +41,29 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port) printf("\n--------------------END-----------------------------\n\n\n"); } +//recieve packets and send them to the packethandler +//run doLossless_UDP(); +void Lossless_UDP() +{ + IP_Port ip_port; + char data[MAX_UDP_PACKET_SIZE]; + uint32_t length; + while(recievepacket(&ip_port, data, &length) != -1) + { + if(LosslessUDP_handlepacket(data, length, ip_port)) + { + printpacket(data, length, ip_port); + } + else + { + printf("Received handled packet with length: %u\n", length); + } + } + + doLossless_UDP(); + +} + int main(int argc, char *argv[]) { @@ -67,12 +90,10 @@ int main(int argc, char *argv[]) int connection; uint64_t timer = current_time(); - IP_Port ip_port; - char data[MAX_UDP_PACKET_SIZE]; - uint32_t length; while(1) { + Lossless_UDP(); connection = incoming_connection(); if(connection != -1) { @@ -89,19 +110,7 @@ int main(int argc, char *argv[]) while(1) { - while(recievepacket(&ip_port, data, &length) != -1) - { - if(LosslessUDP_handlepacket(data, length, ip_port)) - { - printpacket(data, length, ip_port); - } - else - { - printf("Received handled packet with length: %u\n", length); - } - } - - doLossless_UDP(); + Lossless_UDP(); if(is_connected(connection) == 1) { read = read_packet(connection, buffer); -- cgit v1.2.3