#include#include#include#include#include#include#include#include#includeint initiation to link the socket created to the

#include#include#include#include#include#include#include#include#includeint main(int arg, char *argv){int port_no, n, len, soc_created;struct sockaddr_in serv_addr;  /* Structure to define the server address */struct hostent *serv_nam-add;  /* Structure to get the server host address from its name *//* creating the socket at the client */   port_no = atoi(argv2);   soc_created = socket(AF_INET,SOCK_STREAM,0);    if(soc_created<0)      {         printf(" Failure in generating a new socket");         exit(1);      }            /* Getting the server address by resolving it with the name we know */serv_nam-add = gethostbyname(argv1); if(serv_nam-add == 0) {     perror("getting error in gethostbyname");         close(sock);        exit(1);    }    /* Socket address structure to provide the address of the server   which can be obtained by the above used dgehostbyname function*/bzero((char *) &serv_addr, sizeof(serv_addr));serv_addr.sin_family = AF_INET;bcopy((char *)serv_nam-add->h_addr,(char *)&serv_addr.sin_addr.s_addr,serv_nam-add->h_len);serv_addr.sin_port =htons(port_no);/* memset and memcpy can also be used in the place of bzero and bcopy *//* Connect initiation to link the socket created to the server address */n = connect(soc_created, (struct sockaddr *) &serv_addr,sizeof(serv_addr));   if(n<0)    {      printf(" Failure in establishing a connection"); }      else  {       printf(" Successfully established connection"); }/* Work on sending the data and then showing the output that is received bck from the server */char data_gen256;char response256;printf(" Generate the message:");bzero(data_gen,256);read(data_gen,255,stdin);/* Sending the data */n = write(soc_created, data_gen, strlen(data_gen));read(soc_created,response,255);printf("%s ", response);return 0;}

x

Hi!
I'm Mack!

Would you like to get a custom essay? How about receiving a customized one?

Check it out