ofxTCP blocks app

Hi.

I am using oxTCPClient on one mac computer and ofxTCPServer on a second one.
They are are connected directly to each other via an ethernet cable.
one has the IP 192.168.1.100 and the other 192.168.1.101

Everything works great when both computers are on, connected and both apps run.

But my client app freezes if it starts up without the other computer being connected.

Is there a way to check if the other computer is connected before trying to connect to it.
Something using this maybe: SCNetworkReachabilityCreateWithAddress

Thanks,
Stephan.

Hello Stephan,

did the same what you described here with the addon demo (ofxTCPClient & ofxTCPClientServer). Tried everything:

disabled all interfaces
using IP’s that don’t exist
didn’t start the server (software and hardware)

But the demo runs fine and is not blocking if it can not connect and tries to reconnect every 5 seconds.

Did you use the returned bool from ofxTCPClient::setup to see if it could connect?

Regards,
Gestalt

Hello Gestalt.

Just tried the networkTcpClientExample with the following code change:

weConnected = tcpClient.setup(“192.168.1.100”, 11999);

and it did again behave as described in my first post.

if i take this line out of the setup routine, the app starts but hangs once the reconnect timer kicks in.

i have no idea what i am doing different for you ?

s.

here my xcode project as a reference:
www.lozano-hemmer.com/ss/networkTcpClientExample.zip

this might be a work around.
i will try to ping the other computer and if i get a good response only then i will setup the tcpClient.

  
  
        string pingStr = (string)"ping -c 1 -t 1 " + myIP ;  
	int flag = system( pingStr.c_str());   
	cout<<"ping result = "<<flag<<endl;  
        if(flag == 0)	weConnected = tcpClient.setup(myIP, 11999);  
  

the only thing is that this system call is blocking the rest of my app.
maybe i should put it in a separate thread.

s.

Hello Stephan,

did you try to set a breakpoint in the setup mehod of the tcp client to see where it hangs exactly? Are you on the latest github version or do you use 0.61?

Regards,
Gestalt

hi

i tried v0061SL and v0062SL.

i changed the ofxtcpclient a bit so it prints out some info along the way:

here is my modified code:

  
//--------------------------  
bool ofxTCPClient::setup(string ip, int _port, bool blocking){  
  
	cout<<"-> 0"<<endl;  
	  
	if( !TCPClient.Create() ){  
		  
		cout<<"-> 1"<<endl;  
		  
		if(verbose)printf("ofxTCPClient: Create() failed\n");  
		return false;  
		  
	}else {  
		cout<<"-> 2"<<endl;  
		  
		if( !TCPClient.Connect((char *)ip.c_str(), _port) ){  
			  
			cout<<"-> 3"<<endl;  
			  
			if(verbose)printf("ofxTCPClient: Connect(%s, %i) failed\n", ip.c_str(), _port);  
			TCPClient.Close(); //we free the connection  
			return false;  
		}else{  
			cout<<"-> 4"<<endl;  
		}  
	}  
  
	cout<<"-> 5"<<endl;  
	TCPClient.SetNonBlocking(!blocking);  
	  
	cout<<"-> 6"<<endl;  
	  
	port		= _port;  
	ipAddr		= ip;  
	connected	= true;  
	return true;  
}  
  

here are the results:
when both computers are on but only the client is running
-> 0
-> 2
-> 3
ofxTCPClient: Connect(192.168.100.100, 11999) failed

when both computers are on and server and client are running
-> 0
-> 2
-> 4
-> 5
-> 6

when ethernet cable disconnected
-> 0
-> 2

Hello,

It’s been a long time for this post, but i have the same problem today and can’t figure it out !
I’am using oF 0074 + xCode under snow leopard.

Did anyone find a solution ?