Client side implementation of Server-Client system.
More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
|
#define | MAX 80 |
| max. More...
|
|
#define | PORT 8080 |
| port number to connect to
|
|
#define | SA struct sockaddr |
| shortname for sockaddr
|
|
|
void | func (int sockfd) |
| Continuous loop to send and receive over the socket. More...
|
|
int | main () |
| Driver code. More...
|
|
Client side implementation of Server-Client system.
- Author
- Nairit11
-
Krishna Vedala
- See also
- client_server/server.c
◆ MAX
max.
characters per message
◆ func()
Continuous loop to send and receive over the socket.
Exits when "exit" is sent from commandline.
- Parameters
-
sockfd | socket handle number |
43 bzero(buff,
sizeof(buff));
44 printf(
"Enter the string : ");
46 while ((buff[n++] = getchar()) !=
'\n')
50 write(sockfd, buff,
sizeof(buff));
51 bzero(buff,
sizeof(buff));
52 read(sockfd, buff,
sizeof(buff));
53 printf(
"From Server : %s", buff);
54 if ((strncmp(buff,
"exit", 4)) == 0)
56 printf(
"Client Exit...\n");
#define MAX
max.
Definition: client.c:28
◆ main()
Driver code.
75 if (WSAStartup(MAKEWORD(2, 2), &wsData) != 0)
77 perror(
"WSA Startup error: \n");
85 struct sockaddr_in servaddr, cli;
88 sockfd = socket(AF_INET, SOCK_STREAM, 0);
91 printf(
"socket creation failed...\n");
96 printf(
"Socket successfully created..\n");
98 bzero(&servaddr,
sizeof(servaddr));
101 servaddr.sin_family = AF_INET;
102 servaddr.sin_addr.s_addr = inet_addr(
"127.0.0.1");
103 servaddr.sin_port = htons(
PORT);
106 if (connect(sockfd, (
SA *)&servaddr,
sizeof(servaddr)) != 0)
108 printf(
"connection with the server failed...\n");
113 printf(
"connected to the server..\n");
#define SA
shortname for sockaddr
Definition: client.c:30
#define PORT
port number to connect to
Definition: client.c:29
void func(int sockfd)
Continuous loop to send and receive over the socket.
Definition: client.c:37