0% found this document useful (0 votes)
43 views

Chat Application Client

This document contains code for a simple chat client application written in C. The client code establishes a TCP connection to a server on port 45000, allows sending messages to the server until "exit" is received, and prints any messages received from the server until it also receives "exit". The client then closes the socket connection.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Chat Application Client

This document contains code for a simple chat client application written in C. The client code establishes a TCP connection to a server on port 45000, allows sending messages to the server until "exit" is received, and prints any messages received from the server until it also receives "exit". The client then closes the socket connection.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Simple Chat application CLIENT #include"stdio.h" #include"sys/types.h" #include"netinet/in.h" #include"string.h" #include"sys/socket.h" #include"stdlib.h" #include"unistd.

h" int main() { int sd,con,port,i; char content[30]; struct sockaddr_in cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\n Socket problem"); return 0; } bzero((char*)&cli,sizeof(cli)); cli.sin_family = AF_INET; cli.sin_port=htons(45000); cli.sin_addr.s_addr=htonl(INADDR_ANY); con=connect(sd,(struct sockaddr*)&cli,sizeof(cli)); if(con==-1)

{ printf("\n connection error"); return 0; } if(fork()) { printf("\nEnter the data to be send type exit for stop"); scanf("%s",content); while(strcmp(content,"exit")!=0) { send(sd,content,30,0); scanf("%s",content); } send(sd,"exit",5,0); } else { i=recv(sd,content,30,0); while(strcmp(content,"exit")!=0) { printf("Received from server %s\n",content); i=recv(sd,content,30,0); } send(sd,"exit",5,0);

} close(sd); return 0; }

You might also like