Assignment 4
Assignment 4
Assignment:4
Objective: Create a Chat application using TCP socket programming in connection- oriented
Scenario. In Chat application server and client application can chat with each other through text
messages. The chat ends when server or client application sends “exit” message.
Steps
Server Side:
• Include appropriate header files.
• Create a TCP Socket.
• Bind the address and port using bind() system call.
• Server executes listen() system call to indicate its willingness to receive connections.
• Accept the next completed connection from the client process by using an accept() system
call. At this point, connection is established between client and server, and they are ready to
transfer data.
• Receive a message from the Client using recv()/read() system call.
• Send the received message back(echo) to the client using send()/write() system call.
• Close the socket using close() system call
Client Side:
• Include appropriate header files
• Create a TCP Socket.
• Establish connection to the Server using connect() system call.
• Send and recieve messages using send() and recv() system call respectively.
• Close the socket using close() system call
Execution Steps:
o Save client and server program into two separate file with .c extension.
o Open two terminal and execute .c files by following commands
o gcc filename.c –o filename (compilation)
o ./filename (run)