EmbLogic's Blog

ARTICLE

Client sever communication system using socket and multiple thread.

Description: It is a multiple client server project based on TCP socket and threads. Through this infinite number of client can communicate with each other and share information through the server on local network.

In this for i have created individual thread for each and every operation.

SERVER END : Through this all the user can interact with each other. Initially i have created a tcp socket which can be accessed through a combination of ip address and port number. Other calls used in this are BIND to associate your fd which was is your return value of socket call to a structure which contains information regarding your ip address and port number this is basically a naming convention. Then comes your listen call which gives you the number of client which can be held in your socket queue. You can select a port number which is not initialized for any other service. Then through accept call which accepts your client request and provide him a different fd so that it can accept request from new incoming client. Through this different client gets separate fd and can communicate with each other.

For each client there will be an individual thread as soon as a request from client is received, server will create a thread solely for that particular client.

Its has various functionality:

  1. when the first client sends its request to server if it is the only client the server will send him a message that you the only client. So wait till we have another client, then its all upto the client whether he wants to wait or he can quit the server.

  2. Lets say if another client arrive then the server will first send him the option of all the other clients who are still online. And then that client if wishes to connect any of present client it can send his id number to server and server will create a connection between them so that they can share information.

  3. In similar fashion it can connect as many client as asked.

CLIENT END: It include only two system call one is for creating your socket and other one is CONNECT to send a request to your server.

  1. First any of the client will send a request on successful completion of your your socket call in return it will receive a fd through which it can communicate with each other.

  2. As soon as 2 client comes into the picture the server will send him a request of the number of client which are online to select whom he/she wants to connect.

  3. Now our 2 client will have the fd of that client whom he wants to connect but the client on the other hand have no information of the 2nd client which ask the server to connect him to client 1. so before sending any sort of information first the second client will send his fd to 1st client through sever

  4. Now every client has two different thread depending on whether he/she wants to send a request or can directly receiver data if some other client already made a request to connect him to the former client. As we have seen in many social sites that we can receive msg from other client even if are not sending him some information.

This is all about what i have done to date and i am working on it for further amendments.

 Thanks & Regards

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>