CourseLover

(12)

$10/per page/Negotiable

About CourseLover

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Engineering,Health & Medical,HR Management,Law,Marketing,Math,Physics,Psychology,Programming,Science Hide all
Teaching Since: May 2017
Last Sign in: 283 Weeks Ago
Questions Answered: 27237
Tutorials Posted: 27372

Education

  • MCS,MBA(IT), Pursuing PHD
    Devry University
    Sep-2004 - Aug-2010

Experience

  • Assistant Financial Analyst
    NatSteel Holdings Pte Ltd
    Aug-2007 - Jul-2017

Category > Computer Science Posted 25 Dec 2017 My Price 10.00

client-server chat application in C

I am doing this simple client-server chat application in C, to establish socket connection between client and server, and exchange messages between them.

I am able to implement this on 2 different terminals on the same computer.

I want to know how to implement this on two different computers, that is, by dynamically passing IP address and port number during run time.

I am using the following code(Attachments provided)

 

//TCP Client  #include<sys/socket.h>  #include<stdio.h>  #include<string.h>  #include<netdb.h>  #include<stdlib.h>  int main()  {  char buf[100];  int k;  int sock_desc;  struct sockaddr_in client;  memset(&client,0,sizeof(client));  sock_desc=socket(AF_INET,SOCK_STREAM,0);  if(sock_desc==-1)  {  printf("Error in socket creation");  exit(1);  }  client.sin_family=AF_INET;  client.sin_addr.s_addr=INADDR_ANY;  client.sin_port=3002;  k=connect(sock_desc,(struct sockaddr*)&client,sizeof(client));  if(k==-1)  {  printf("Error in connecting to server");  exit(1);  }  while(1)  {  printf("\nEnter data to be send to server: ");  fgets(buf,100,stdin);  if(strncmp(buf,"end",3)==0)//Use  to end communication with server break;  k=send(sock_desc,buf,100,0);  if(k==-1)  {  printf("Error in sending");  exit(1);  }  k=recv(sock_desc,buf,100,0);  if(k==-1)  { 

 

Background image of page 1
 
printf("Error in receiving");  exit(1);  }  printf("Message got from server is : %s",buf);  }  close(sock_desc);  exit(0);  return 0;  } 
Background image of page 2
Background image of page 1
 
} close(temp_sock_desc); exit(0); return 0; }
Background image of page 2

Answers

(12)
Status NEW Posted 25 Dec 2017 01:12 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------usi-----------ng -----------our----------- we-----------bsi-----------te -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------ns.----------- Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m o-----------nli-----------ne -----------or -----------inb-----------ox -----------me -----------a m-----------ess-----------age-----------

Not Rated(0)