Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
client.c File Reference

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>
Include dependency graph for client.c:

Macros

#define MAX   80
 max. More...
 
#define PORT   8080
 port number to connect to
 
#define SA   struct sockaddr
 shortname for sockaddr
 

Functions

void func (int sockfd)
 Continuous loop to send and receive over the socket. More...
 
int main ()
 Driver code.
 

Detailed Description

Client side implementation of Server-Client system.

Author
Nairit11
Krishna Vedala
See also
client_server/server.c

Macro Definition Documentation

◆ MAX

#define MAX   80

max.

characters per message

Function Documentation

◆ func()

void func ( int  sockfd)

Continuous loop to send and receive over the socket.

Exits when "exit" is sent from commandline.

Parameters
sockfdsocket handle number
38 {
39  char buff[MAX];
40  int n;
41  for (;;)
42  {
43  bzero(buff, sizeof(buff));
44  printf("Enter the string : ");
45  n = 0;
46  while ((buff[n++] = getchar()) != '\n')
47  {
48  ;
49  }
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)
55  {
56  printf("Client Exit...\n");
57  break;
58  }
59  }
60 }
#define MAX
max.
Definition: client.c:28