11-04-2014, 02:24 PM
SOCKET PROGRAMMING
AIM
To write a C program for implementing Client-Server Chat using TCP.
ALGORITHM
SERVER
Step 1: Start the program.
Step 2: Create an unnamed socket for the server using the
parameters AF_INET as domain and the SOCK_STREAM as type.
Step 3: Name the socket using bind( ) system call with the
parameters server_sockfd and the server address(sin_addr and sin_sport).
Step 4: Create a connection queue and wait for clients using the listen( ) system call
with the number of clients request as parameters.
Step 5: Accept the connection using accept( ) system call when client requests for
connection.
Step 6: Get the message which has to be sent to the client and check that it is not
equal to ‘Bye’.
Step 7: If the message is not equal to ‘Bye’ then write the message to the client and
Goto step 6.
Step 8: If the message is ‘Bye’ then terminate the Process.
Step 9: Stop the program execution.
CLIENT
Step 1: Start the program.
Step 2: Create an unnamed socket for client using socket( ) system.
Step 3: Call with parameters AF_INET as domain and SOCK_STREAM as type.
Step 4: Name the socket using bind( ) system call.
Step 5: Now connect the socket to server using connect( ) system call.
Step 6: Read the message from the server socket and compare it with ‘Bye’.
Step 7: If the message is not equal to ‘Bye’ then print the message to the server
output device and repeat the steps 6 & 7.
Step 8: Get the message from the client side.
Step 9: Write the message to server sockfd and goto step 4.
Step 10:If the message is equal to ‘Bye’then print good bye message and terminate
the process.
Step 11:Stop the process.
RESULT
Thus the C program for chat using TCP is executed and the output is verified successfully