diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 44 | ||||
-rw-r--r-- | testing/Lossless_UDP_testserver.c | 43 |
2 files changed, 52 insertions, 35 deletions
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 @@ | |||
3 | * | 3 | * |
4 | * Best used in combination with Lossless_UDP_testserver | 4 | * Best used in combination with Lossless_UDP_testserver |
5 | * | 5 | * |
6 | * Compile with: gcc -O2 -Wall -o test ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testclient.c | 6 | * Compile with: gcc -O2 -Wall -o testclient ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testclient.c |
7 | * | 7 | * |
8 | * Command line arguments are the ip and port to cennect and send the file to. | 8 | * Command line arguments are the ip and port to cennect and send the file to. |
9 | * EX: ./test 127.0.0.1 33445 filename.txt | 9 | * EX: ./test 127.0.0.1 33445 filename.txt |
@@ -40,6 +40,29 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port) | |||
40 | printf("\n--------------------END-----------------------------\n\n\n"); | 40 | printf("\n--------------------END-----------------------------\n\n\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | //recieve packets and send them to the packethandler | ||
44 | //run doLossless_UDP(); | ||
45 | void Lossless_UDP() | ||
46 | { | ||
47 | IP_Port ip_port; | ||
48 | char data[MAX_UDP_PACKET_SIZE]; | ||
49 | uint32_t length; | ||
50 | while(recievepacket(&ip_port, data, &length) != -1) | ||
51 | { | ||
52 | if(LosslessUDP_handlepacket(data, length, ip_port)) | ||
53 | { | ||
54 | printpacket(data, length, ip_port); | ||
55 | } | ||
56 | else | ||
57 | { | ||
58 | printf("Received handled packet with length: %u\n", length); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | doLossless_UDP(); | ||
63 | |||
64 | } | ||
65 | |||
43 | 66 | ||
44 | int main(int argc, char *argv[]) | 67 | int main(int argc, char *argv[]) |
45 | { | 68 | { |
@@ -68,7 +91,7 @@ int main(int argc, char *argv[]) | |||
68 | uint64_t timer = current_time(); | 91 | uint64_t timer = current_time(); |
69 | while(1) | 92 | while(1) |
70 | { | 93 | { |
71 | 94 | Lossless_UDP(); | |
72 | if(is_connected(connection) == 3) | 95 | if(is_connected(connection) == 3) |
73 | { | 96 | { |
74 | printf("Connecting took: %llu us", (unsigned long long)(current_time() - timer)); | 97 | printf("Connecting took: %llu us", (unsigned long long)(current_time() - timer)); |
@@ -83,28 +106,13 @@ int main(int argc, char *argv[]) | |||
83 | } | 106 | } |
84 | timer = current_time(); | 107 | timer = current_time(); |
85 | 108 | ||
86 | IP_Port ip_port; | ||
87 | char data[MAX_UDP_PACKET_SIZE]; | ||
88 | uint32_t length; | ||
89 | 109 | ||
90 | //read first part of file | 110 | //read first part of file |
91 | read = fread(buffer, 1, 128, file); | 111 | read = fread(buffer, 1, 128, file); |
92 | 112 | ||
93 | while(1) | 113 | while(1) |
94 | { | 114 | { |
95 | while(recievepacket(&ip_port, data, &length) != -1) | 115 | Lossless_UDP(); |
96 | { | ||
97 | if(LosslessUDP_handlepacket(data, length, ip_port)) | ||
98 | { | ||
99 | printpacket(data, length, ip_port); | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | printf("Received handled packet with length: %u\n", length); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | doLossless_UDP(); | ||
108 | 116 | ||
109 | if(is_connected(connection) == 1) | 117 | if(is_connected(connection) == 1) |
110 | { | 118 | { |
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 @@ | |||
3 | * | 3 | * |
4 | * Best used in combination with Lossless_UDP_testclient | 4 | * Best used in combination with Lossless_UDP_testclient |
5 | * | 5 | * |
6 | * Compile with: gcc -O2 -Wall -o test ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testserver.c | 6 | * Compile with: gcc -O2 -Wall -o testserver ../core/network.c ../core/Lossless_UDP.c Lossless_UDP_testserver.c |
7 | * | 7 | * |
8 | * Command line argument is the name of the file to save what we recieve to. | 8 | * Command line argument is the name of the file to save what we recieve to. |
9 | * EX: ./test filename1.txt | 9 | * EX: ./test filename1.txt |
@@ -41,6 +41,29 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port) | |||
41 | printf("\n--------------------END-----------------------------\n\n\n"); | 41 | printf("\n--------------------END-----------------------------\n\n\n"); |
42 | } | 42 | } |
43 | 43 | ||
44 | //recieve packets and send them to the packethandler | ||
45 | //run doLossless_UDP(); | ||
46 | void Lossless_UDP() | ||
47 | { | ||
48 | IP_Port ip_port; | ||
49 | char data[MAX_UDP_PACKET_SIZE]; | ||
50 | uint32_t length; | ||
51 | while(recievepacket(&ip_port, data, &length) != -1) | ||
52 | { | ||
53 | if(LosslessUDP_handlepacket(data, length, ip_port)) | ||
54 | { | ||
55 | printpacket(data, length, ip_port); | ||
56 | } | ||
57 | else | ||
58 | { | ||
59 | printf("Received handled packet with length: %u\n", length); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | doLossless_UDP(); | ||
64 | |||
65 | } | ||
66 | |||
44 | 67 | ||
45 | int main(int argc, char *argv[]) | 68 | int main(int argc, char *argv[]) |
46 | { | 69 | { |
@@ -67,12 +90,10 @@ int main(int argc, char *argv[]) | |||
67 | int connection; | 90 | int connection; |
68 | uint64_t timer = current_time(); | 91 | uint64_t timer = current_time(); |
69 | 92 | ||
70 | IP_Port ip_port; | ||
71 | char data[MAX_UDP_PACKET_SIZE]; | ||
72 | uint32_t length; | ||
73 | 93 | ||
74 | while(1) | 94 | while(1) |
75 | { | 95 | { |
96 | Lossless_UDP(); | ||
76 | connection = incoming_connection(); | 97 | connection = incoming_connection(); |
77 | if(connection != -1) | 98 | if(connection != -1) |
78 | { | 99 | { |
@@ -89,19 +110,7 @@ int main(int argc, char *argv[]) | |||
89 | 110 | ||
90 | while(1) | 111 | while(1) |
91 | { | 112 | { |
92 | while(recievepacket(&ip_port, data, &length) != -1) | 113 | Lossless_UDP(); |
93 | { | ||
94 | if(LosslessUDP_handlepacket(data, length, ip_port)) | ||
95 | { | ||
96 | printpacket(data, length, ip_port); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | printf("Received handled packet with length: %u\n", length); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | doLossless_UDP(); | ||
105 | if(is_connected(connection) == 1) | 114 | if(is_connected(connection) == 1) |
106 | { | 115 | { |
107 | read = read_packet(connection, buffer); | 116 | read = read_packet(connection, buffer); |