Client side implementation of UDP client-server model.
More...
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
|
#define | PORT 8080 |
| port number to connect to
|
|
#define | MAXLINE 1024 |
| maximum characters per line
|
|
Client side implementation of UDP client-server model.
- Author
- TheShubham99
-
Krishna Vedala
- See also
- client_server/udp_server.c
◆ main()
Driver code.
40 if (WSAStartup(MAKEWORD(2, 2), &wsData) != 0)
42 perror(
"WSA Startup error: \n");
51 char *hello =
"Hello from client";
52 struct sockaddr_in servaddr;
55 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
57 perror(
"socket creation failed");
61 memset(&servaddr, 0,
sizeof(servaddr));
64 servaddr.sin_family = AF_INET;
65 servaddr.sin_port = htons(
PORT);
66 servaddr.sin_addr.s_addr = INADDR_ANY;
71 sendto(sockfd, (
const char *)hello, strlen(hello), 0,
72 (
const struct sockaddr *)&servaddr,
sizeof(servaddr));
73 printf(
"Hello message sent.\n");
76 (
struct sockaddr *)&servaddr, &len);
78 printf(
"Server : %s\n",
buffer);
struct used to store character in certain times
Definition: min_printf.h:31
#define MAXLINE
maximum characters per line
Definition: udp_client.c:27
#define PORT
port number to connect to
Definition: udp_client.c:26