simple tcp questions

hi all,

what exactly does the blocking true/false flag in tcp client / server do?

how come in the tcp server, there is always a connected client on 000.000.000.000 on port 0?

using the tcp server and client examples, the client tries to reconnect after 5 seconds.

if i connect the client to the server, then quit the server, the errors I get back from the client in the console are:

ofxTCPClient: sendAll() failed
ofxTCPClient: Create() failed
ofxTCPClient: Create() failed
ofxTCPClient: Create() failed

any ideas why this might be?

when i restart the tcp server, it is unable to connect (still the messages above), if restarting server whilst client is still running. however if i exit and restart client, it connects fine.

this is in windows on the localhost 127.0.0.1

any ideas would be great!

many thanks

what exactly does the blocking true/false flag in tcp client / server do?

when you try to read it blocks till there’s some data available, if it’s not blocking it just returns.

if i connect the client to the server, then quit the server, the errors I get back from the client in the console are:

ofxTCPClient: sendAll() failed
ofxTCPClient: Create() failed
ofxTCPClient: Create() failed
ofxTCPClient: Create() failed

any ideas why this might be?

the first one is trying to send but it can’t because the server doesn’t exists anymore so it disconnects. the second is trying to create the connection to the the server but it can’t because there’s no server.

when i restart the tcp server, it is unable to connect (still the messages above), if restarting server whilst client is still running. however if i exit and restart client, it connects fine.

it could be that the server is not closing the port correctly when you exit or that the client doesn’t close the port correctly when it detects a disconnection, will look into it

hey arturo

just to let you know, i tried the latest ofxNetwork from github and I get the same issue described above. I am on Windows using codeblocks.

thanks
chris

So just doing a printf, it is failing here in ofxTCPManager::Create

if (m_hSocket != INVALID_SOCKET){
printf(“m_hSocket\n”);
return(false);

i’m testing and the only problem i’ve seen is that the server is not removing the disconnected clients. i’ve fixed it but apart from that i can kill both the client and server and restart them and everything works without problem.

if the problem persists perhaps you can close the connections explicitly in the exit method of testApp, just in case your app is crashing on exist or something weird that makes the socket to not be closed properly

Hello, I think I am having a similar problem related to ofxTCPServer retaining disconnected clients. I’m using Windows 7, and openFrameworks v0.062. In oF I start up an instance of ofxTCPServer, then as soon as I connect to it with an external client, the console is immediately flooded with this message:

  
  
OF_ERROR: ofxNetwork:c:dev\of\addons\ofxnetwork\src\ofxtcpmanager.cpp: 304 unknown error: 0 see errno.h for description of the error  
  

When I trace through, I see that the errno value is 10054 - meaning a fairly innocuous “An existing connection was forcibly closed by the remote host”

I grabbed your edits from gitHub:
https://github.com/openframeworks/openFrameworks/commit/d9e73b2c43b40734d13f582a7133a1ff9e05d308

But I am still having the same problem. If I try to disconnect the clients manually, I frequently run into heap corruptions, because ofxTCPServer is not thread-safe (not even internally).

Functionally, communications seem to work, but I can’t use the console, even with verbose set to false everywhere. Any ideas on how I can fix this?

try using the addon from 007 on github, all those errors have been fixed there. from chris’ comments i think the only thing necessary to make it work is change ofThread with ofxThread

don’t use the individual repo for ofxNetwork but the one in the openFrameworks repository:

http://github.com/openframeworks/openFrameworks

Thanks for the suggestion, I grabbed a complete copy of the latest master branch from github.

I don’t see the trace anymore when I connect. But immediately after I disconnect, the console is flooded with this:

  
  
OF: OF_LOG_ERROR: ofxNetwork:c:\dev\of\addons\ofxnetwork\src\ofxtcpmanager.cpp:  
304 ECONNRESET: connection closed by peer  
  

However, the real problem is that when I try to reconnect again I get a C++ debug assertion:

  
Expression: map/set iterator not incrementable  

I know why this happens, because I am iterating over the possible clients in a separate thread like this:

  
  
map<int,ofxTCPClient>::iterator it;  
for(it=_tcpServer->TCPConnections.begin(); it!=_tcpServer->TCPConnections.end(); it++){  
..  
}  
  

This causes a problem when the next client connects and the map is updated on its own thread. What is canonical way to poll for received messages?

I noticed that the networkTcpServerExample is broken because it iterates from 0 to the number of clients:

  
  
for(int i = 0; i < TCP.getNumClients(); i++){  
string str = TCP.receive(i);  
}  
  

But, when the first client connects and disconnects, the clientids are incremented but the iterator will never get there.

Help?