11-04-2014, 02:33 PM
MULTICLIENT-SERVER CHAT
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: Get the client’s id as input from the user to communicate. If the client’s id is 0 then go to step 10 otherwise go to step 6.
Step 6: Accept the connection using accept ( ) system call when client requests for connection.
Step 7: Get the message which has to be sent to the client and check that it is not equal to ‘Bye’.
Step 8: If the message is not equal to ‘Bye’ then write the message to the client and Goto step 6.
Step 9: If the message is ‘Bye’ then terminates the connection with current client and Go to
step 5.
Step 10: 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’.
RESULT
Thus the C program for chat multiclient-serve chat program using tcp has been executed successfully.