Thing is that's exctly what I done before this approach. Here's a similar code that I tried, where I create an array of sessions and look for the first one that's available, and use that one to accept a new connection. I have exactly the same problem: First client connects well, we can communicate, I receive his messages and I can send him messages back.
Then, whenever a second client tries to connect it's automatically disconnected. Also, if i disconnect the first client and try to connect him back, he also can't connect anymore, gets instantly disconnected.
Here's a log of what I mean:
Connected: 0 //client "0" connects with netcat
Received from 0 : a //client sends messages
Received from 0 : b
Received from 0 : c
Connected: 1 //client "1" connects with netcat
Disconnected: 1 //disconected immediately
Disconnected: 0 //I close the connection of clent "0"
Connected: 0 // I try to connect again with client "0"
Disconnected: 0 //Same problem as client "1"
Connected: 0
Disconnected: 0
Mihai