TCP chat client and server application Code

TCP chat client and server application

 

Problem Statement : Write a C Language Program to perform TCP chat client and server application.

TCP chat client and server uses TCP as protocol for sending and receiving data from server. Server.c is server which waits for client to send data. User can enter q or Q for quitting the Chat program.

Server is using port number 5000 to contact Client. After accepting connection both server and client can exchange messages. TCP chat client and server program is using TCP protocol to exchange data packets between client.c and server.c

Server Code

[button style=”large green  embossed” link=”https://sites.google.com/site/codesgeeks/codesgeek_1/TCP%20chat%20client%20and%20server-server.c” target=”_blank” ]Server Code Download[/button]

Client Program

 [button style=”large green  embossed” link=”https://sites.google.com/site/codesgeeks/codesgeek_1/TCP%20chat%20client%20and%20server-client.c” target=”_blank” ]Client Code Download[/button]

TCP chat client and server Output

Sample Output 1

mint@mint ~ $ ./server

TCPServer Waiting for client on port 5000
 I got a connection from (127.0.0.1 , 37093)
 SEND (q or Q to quit) : Hello

 RECIEVED DATA = Welcome
 SEND (q or Q to quit) : Good

 RECIEVED DATA = BAD  
 SEND (q or Q to quit) : UGLY

 RECIEVED DATA = AMERICA
 SEND (q or Q to quit) :

mint@mint ~ $ ./client

Recieved data = Hello
SEND (q or Q to quit) : Welcome

Recieved data = Good
SEND (q or Q to quit) : BAD

Recieved data = UGLY
SEND (q or Q to quit) : AMERICA