Connected or not connected !

Hello !

I've got a question . I really don't het this point. Let's supose that I have a client connected to a server.

I want the server IMEDIATLY know if the client is diconnected . How can I realize this ? :mad:

Amd I'm just curios about one thing. I have a server and multiple clients connected to it. Yes , multithreading . Each client connects to 3 ports on the server. So for each client the server will be opening a socket descriptor .Let's take an example : ( the server is using 3 threads with select , for each socket - 3 ports).

 
Server will use 3 socket descriptors : 3,4,5 .
Client one will use ( the next )  : 6,7,8.
Client  two  will use : 9,10,11 .and so on so fort..
Client  three  will use : 12,13,14 ..
etc..

If , per example client 1 is disconnected ( from all 3 sockets ) , select from server ( all 3 threads ) will connect another client on : 6,7,8 , because they're free..

Good , what do I mean to ask ? How can I know which socket descriptors is using a client ? I mean where do I know client 1 is using : 6 , 7 , 8 ?

I mean a problem like this :

Client 1 is disconnected . But it only disconnect two sockets from the server , so 6,7 socket descriptors are free , but 8 remain full ( because the clients hasent's disconnected ).

So the server ( 3 threads ) with select on each will make the following thing.If another client is connected it will use : 6,7 and the the first free socket descritor in our example if 15.
So client 1 will have : 6,7,15 open socket descriptors at server side.

I want to know clearly on the server side , which socket descriptors numbers are used by each client. I cannot say that they're always be in a numbered way : n,n+1,n-1 . How can I know . Maybe is a stupid question , but .. :confused:

hello !
it is been a long time since u post your problem, so are u having same problems as mentioned ? or solved ? :slight_smile: if not it might be a solution.

Same problem.

Which is the solution ? :smiley: ( You were talking about ? ).

hello ! :slight_smile:

ok the solution to this is by means to implement an algorithm -a way- to take care of when the ports will open and when will close, so u will have track all the time of what is going on with the ports. there is no direct way to deal with it.

for example
in your approach
when a peer is connected u open 3 ports, make sure that when it disconnects, it frees up all the ports. no exept. so the u will have your n+1

as u may think there are numerous way to deal with this. :slight_smile:
so the think u need to do is find "a way" in design lvl rather than digging out functions. :slight_smile: