-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
37 lines (29 loc) · 938 Bytes
/
Copy pathclient.c
File metadata and controls
37 lines (29 loc) · 938 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
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
int port = 6789;
int main(int argc, char** argv){
int socket_descriptor;
int iter = 0;
char buf[80];
struct sockaddr_in address;
bzero(&address, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("127.0.0.1");
address.sin_port = htons(port);
socket_descriptor = socket(AF_INET, SOCK_DGRAM, 0);
for(iter = 0; iter<20; iter++){
sleep(1);
sprintf(buf, "data packet with ID %d\n", iter);
sendto(socket_descriptor, buf, sizeof(buf), 0, (struct sockaddr *)&address, sizeof(address));
}
sprintf(buf, "stop\n");
sendto(socket_descriptor, buf, sizeof(buf), 0, (struct sockaddr *) &address, sizeof(address));
close(socket_descriptor);
printf("Messages Sent, terminating\n");
return (EXIT_SUCCESS);
}