-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
27 lines (21 loc) · 687 Bytes
/
client.c
File metadata and controls
27 lines (21 loc) · 687 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
#include <stdio.h>
#include "udp.h"
#define BUFFER_SIZE (1000)
// client code
int main(int argc, char *argv[]) {
struct sockaddr_in addrSnd, addrRcv;
int sd = UDP_Open(20000);
int rc = UDP_FillSockAddr(&addrSnd, "localhost", 10000);
char message[BUFFER_SIZE];
sprintf(message, "hello world");
printf("client:: send message [%s]\n", message);
rc = UDP_Write(sd, &addrSnd, message, BUFFER_SIZE);
if (rc < 0) {
printf("client:: failed to send\n");
exit(1);
}
printf("client:: wait for reply...\n");
rc = UDP_Read(sd, &addrRcv, message, BUFFER_SIZE);
printf("client:: got reply [size:%d contents:(%s)\n", rc, message);
return 0;
}