forked from remzi-arpacidusseau/ostep-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
28 lines (22 loc) · 621 Bytes
/
Copy pathserver.c
File metadata and controls
28 lines (22 loc) · 621 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include "udp.h"
#define BUFFER_SIZE (1000)
// server code
int main(int argc, char *argv[]) {
int sd = UDP_Open(10000);
assert(sd > -1);
while (1) {
struct sockaddr_in addr;
char message[BUFFER_SIZE];
printf("server:: waiting...\n");
int rc = UDP_Read(sd, &addr, message, BUFFER_SIZE);
printf("server:: read message [size:%d contents:(%s)]\n", rc, message);
if (rc > 0) {
char reply[BUFFER_SIZE];
sprintf(reply, "goodbye world");
rc = UDP_Write(sd, &addr, reply, BUFFER_SIZE);
printf("server:: reply\n");
}
}
return 0;
}