summaryrefslogtreecommitdiff
path: root/testing/Lossless_UDP_testserver.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/Lossless_UDP_testserver.c')
-rw-r--r--testing/Lossless_UDP_testserver.c43
1 files changed, 26 insertions, 17 deletions
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();
46void 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
45int main(int argc, char *argv[]) 68int 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);