| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <unistd.h>
|
|---|
| 4 | #include <string.h>
|
|---|
| 5 | #include <sys/types.h>
|
|---|
| 6 | #include <sys/socket.h>
|
|---|
| 7 | #include <netinet/in.h>
|
|---|
| 8 | #include <netdb.h>
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | /// working
|
|---|
| 13 | //#define MESSAGE_SIZE 1 * 1024
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | //not working
|
|---|
| 17 | #define MESSAGE_SIZE 4 * 1024
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | int main(int argc, char *argv[])
|
|---|
| 21 | {
|
|---|
| 22 | char DATA[MESSAGE_SIZE];
|
|---|
| 23 | int i = 0;
|
|---|
| 24 | for (; i < MESSAGE_SIZE ; i++) {
|
|---|
| 25 | DATA[i]= '.';
|
|---|
| 26 | }
|
|---|
| 27 | int sock;
|
|---|
| 28 | struct sockaddr_in server;
|
|---|
| 29 |
|
|---|
| 30 | if (argc != 3) {
|
|---|
| 31 | fprintf(stderr, "USAGE: %s <server_ip> <port>\n", argv[0]);
|
|---|
| 32 | exit(1);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
|---|
| 36 | perror("socket");
|
|---|
| 37 | exit(1);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | memset(&server, 0, sizeof(server));
|
|---|
| 41 | server.sin_family = AF_INET;
|
|---|
| 42 | server.sin_addr.s_addr = inet_addr(argv[1]);
|
|---|
| 43 | server.sin_port = htons(atoi(argv[2]));
|
|---|
| 44 |
|
|---|
| 45 | for (;;) {
|
|---|
| 46 | if (sendto(sock, DATA, MESSAGE_SIZE , 0,
|
|---|
| 47 | (struct sockaddr *) &server,
|
|---|
| 48 | sizeof(server)) != MESSAGE_SIZE) {
|
|---|
| 49 | perror("sendto");
|
|---|
| 50 | exit(1);
|
|---|
| 51 | }
|
|---|
| 52 | sleep(1);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | return 0;
|
|---|
| 56 | }
|
|---|