Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofxTCPServer doesn't manage connected clients correcly #128

Closed
arturoc opened this issue Feb 14, 2010 · 9 comments
Closed

ofxTCPServer doesn't manage connected clients correcly #128

arturoc opened this issue Feb 14, 2010 · 9 comments

Comments

@arturoc
Copy link
Member

arturoc commented Feb 14, 2010

http://www.openframeworks.cc/forum/viewtopic.php?f=10&t=3319

@arturoc
Copy link
Member Author

arturoc commented Apr 26, 2010

ofxTCPServer: fix for client disconnection. Closed by cb4ba37

@gameoverhack
Copy link
Contributor

Hey Arturo I think there is a problem with some of these changes; in particular:

bool ofxTCPServer::sendToAll(string message) {
if(TCPConnections.size() == 0) return false;

map<int,ofxTCPClient>::iterator it;
vector<int> disconnect;
for(it=TCPConnections.begin(); it!=TCPConnections.end(); it++){
    int err = 0;
    if(it->second.isConnected()) err = it->second.send(message);
    if(!TCPConnections[it->first].isConnected()) disconnect.push_back(it->first);
}
for(int i=0; i<(int)disconnect.size(); i++){
    TCPConnections.erase(disconnect[i]);
}
return true;

}

will disconnect a valid TCP connection...I haven't gone hunting in-depth, but I see that getNumClients returns TCPConnections.size()-1; so I'm assuming that [0] is the server? or reserved? somehow that scrambles the logic of how connections are being stored in the map...

For now I'm just commenting out the disconnection lines...I'm happy to pursue further but figure you'll see the problem faster ;-)

@gameoverhack
Copy link
Contributor

For now I'm doing:

if(!TCPConnections[it->first].isConnected() && it->first < TCPConnections.size()-1) disconnect.push_back(it->first);

but I don't really understand what ofxTCPClient is being stored in the map before I make a connection...is it the server itself that is being stored in the map first?

@santa41116
Copy link

Was this issue fixed after all?
I'm having problems with getNumClients in connection with disconnectClient. Once a new client connects after disconnecting an old one, getNumClients increases by 2 and sendToAll results in an error.

@bilderbuchi bilderbuchi reopened this Mar 12, 2012
@Drosen
Copy link

Drosen commented Mar 28, 2013

As far as I can tell this is still an issue. SendToAll will disconnect a client.
gameoverhack's solution worked for me.

@bilderbuchi
Copy link
Member

Pushing back issues without assignee to 0.8.1.

@ghost ghost assigned arturoc Jul 11, 2013
@ofTheo
Copy link
Member

ofTheo commented Jul 15, 2013

@arturoc - could you take another look at this, would be great to fix for 0.8 ?

@arturoc
Copy link
Member Author

arturoc commented Jul 15, 2013

i think i fixed it already in a later commit, but i need to check. will do it in a moment

@arturoc
Copy link
Member Author

arturoc commented Jul 15, 2013

i've tested with several clients and sendToAll and this seems to be fixed, indeed the line @gameoverhack points as the problem doesn't exist anymore.

@arturoc arturoc closed this as completed Jul 15, 2013
ofTheo pushed a commit to ofTheo/openFrameworks that referenced this issue Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants