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.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
index 9a180cbb..5370da9e 100644
--- a/testing/Lossless_UDP_testserver.c
+++ b/testing/Lossless_UDP_testserver.c
@@ -1,5 +1,6 @@
1/* Lossless_UDP testserver 1/* Lossless_UDP testserver
2 * A program that waits for a lossless UDP connection and then saves all the data recieved to a file. 2 * A program that waits for a lossless UDP connection and then saves all the data recieved to a file.
3 * NOTE: this program simulates a 33% packet loss.
3 * 4 *
4 * Best used in combination with Lossless_UDP_testclient 5 * Best used in combination with Lossless_UDP_testclient
5 * 6 *
@@ -40,6 +41,7 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port)
40 } 41 }
41 printf("\n--------------------END-----------------------------\n\n\n"); 42 printf("\n--------------------END-----------------------------\n\n\n");
42} 43}
44/*
43void printpackets(Data test) 45void printpackets(Data test)
44{ 46{
45 int i; 47 int i;
@@ -75,14 +77,14 @@ void printconnection(int connection_id)
75 } 77 }
76 Data sendbuffer[MAX_QUEUE_NUM]; 78 Data sendbuffer[MAX_QUEUE_NUM];
77 Data recvbuffer[MAX_QUEUE_NUM]; 79 Data recvbuffer[MAX_QUEUE_NUM];
78 printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n", 80 printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
79 connections[connection_id].recv_packetnum, 81 connections[connection_id].recv_packetnum,
80 connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum, 82 connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
81 connections[connection_id].successful_sent, 83 connections[connection_id].successful_sent,
82 connections[connection_id].successful_read); 84 connections[connection_id].successful_read);
83 85
84 printf("req packets: \n"); 86 printf("req packets: \n");
85 for(i = 0; i < MAX_PACKET_NUM; i++) 87 for(i = 0; i < BUFFER_PACKET_NUM; i++)
86 { 88 {
87 printf(" %u ", connections[connection_id].req_packets[i]); 89 printf(" %u ", connections[connection_id].req_packets[i]);
88 } 90 }
@@ -92,7 +94,7 @@ void printconnection(int connection_id)
92 printf("--------------------END---------------------\n"); 94 printf("--------------------END---------------------\n");
93 95
94} 96}
95 97*/
96//recieve packets and send them to the packethandler 98//recieve packets and send them to the packethandler
97//run doLossless_UDP(); 99//run doLossless_UDP();
98void Lossless_UDP() 100void Lossless_UDP()
@@ -103,14 +105,16 @@ void Lossless_UDP()
103 while(recievepacket(&ip_port, data, &length) != -1) 105 while(recievepacket(&ip_port, data, &length) != -1)
104 { 106 {
105 if(rand() % 3 != 1)//add packet loss 107 if(rand() % 3 != 1)//add packet loss
106 if(LosslessUDP_handlepacket(data, length, ip_port))
107 {
108 printpacket(data, length, ip_port);
109 }
110 else
111 { 108 {
112 // printconnection(0); 109 if(LosslessUDP_handlepacket(data, length, ip_port))
113 printf("Received handled packet with length: %u\n", length); 110 {
111 printpacket(data, length, ip_port);
112 }
113 else
114 {
115 //printconnection(0);
116 // printf("Received handled packet with length: %u\n", length);
117 }
114 } 118 }
115 } 119 }
116 120
@@ -151,13 +155,14 @@ int main(int argc, char *argv[])
151 connection = incoming_connection(); 155 connection = incoming_connection();
152 if(connection != -1) 156 if(connection != -1)
153 { 157 {
154 if(is_connected(connection) == 3) 158 if(is_connected(connection) == 2)
155 { 159 {
156 printf("Recieved the connection.\n"); 160 printf("Recieved the connection.\n");
161
157 } 162 }
158 break; 163 break;
159 } 164 }
160 c_sleep(100); 165 c_sleep(1);
161 } 166 }
162 167
163 timer = current_time(); 168 timer = current_time();
@@ -166,13 +171,13 @@ int main(int argc, char *argv[])
166 { 171 {
167 //printconnection(0); 172 //printconnection(0);
168 Lossless_UDP(); 173 Lossless_UDP();
169 if(is_connected(connection) == 3) 174 if(is_connected(connection) >= 2)
170 { 175 {
171 read = read_packet(connection, buffer); 176 read = read_packet(connection, buffer);
172 177
173 if(read != 0) 178 if(read != 0)
174 { 179 {
175 printf("Recieved data.\n"); 180 // printf("Recieved data.\n");
176 if(!fwrite(buffer, read, 1, file)) 181 if(!fwrite(buffer, read, 1, file))
177 { 182 {
178 printf("file write error\n"); 183 printf("file write error\n");
@@ -185,7 +190,7 @@ int main(int argc, char *argv[])
185 fclose(file); 190 fclose(file);
186 return 1; 191 return 1;
187 } 192 }
188 c_sleep(50); 193 c_sleep(1);
189 } 194 }
190 195
191 return 0; 196 return 0;