I can only run my TCP application once and then it showed me the following error:
OF_ERROR: ofxNetwork:/Users/…/Code/of_preRelease_v0062_osxSL_FAT/apps/examples/…/ofxTCPManager.cpp: 104 EADDRINUSE: the socket address of the given addr is already in use
ofxTCPServer: bind(port = 1638) failed
I tried to close the socket on exit but it doesn’t help. it works again after i restart my laptop, but just once. is there anyway to resolve this? thanks.
Two quick things: a) If you can, you should probably update to 007, it’s available at http://openframeworks.cc/download, there’s a lot of cool new stuff in there and b) depending on how you’ve configured your server you might need to call ofxTCPManager::Close() to ensure that port isn’t in use after the application exit.
I did ofxTCPServer.close() and ofxTCPManager.close() on exit, but it still doesn’t work. it shows the same error. i run the networkTcpClientExample/networkTcpServerExample, it works fine with other ports. is there any other way to unbind those ports? or make sure socket address is not used after exit.
It looks like you are on Mac so this is a trick I use as opposed to rebooting your machine.
Go to System Preferences>Network
In the Location dropdown select “Edit Locations”
Hit the + button to create a new Location and call it “DISABLED”
Select each Ethernet Adapter on the left and under the “Configure IPv4” drop down select off
So when you get the port error message you can basically reboot your ports by selecting “DISABLED” and Apply and then switching back to your regular Location (usually “Automatic”). Locations also available under the Apple Menu.
There probably is a quicker Terminal way of doing this but this has been the easiest way to show other people not Terminal-friendly
Thanks!
I tried it and also tested different port, but it still gives me the same error:
OF_ERROR: ofxNetwork:/Users/…/Code/of_preRelease_v0062_osxSL_FAT/apps/examples/…/ofxTCPManager.cpp: 104 EADDRINUSE: the socket address of the given addr is already in use
ofxTCPServer: bind(port = 50001) failed
will there be any other reason? I don’t have my firewall on.
here is how i initialize TCPsocket as server:
in testApp.h
ofxTCPServer TCP1;
in testApp.cpp
setup()
TCP1.setup(50001);
update()
// nothing, since i’m not sending anything
draw()
// basically same code from networkTcpServerExample, just print out whatever receives
for(int i = 0; i < TCP1.getNumClients(); i++){
string port = ofToString( TCP1.getClientPort(i) );
string ip = TCP1.getClientIP(i);
string info = "client “+ofToString(i)+” -connected from “+ip+” on port: "+port;
if(i >= storeText.size() ){
storeText.push_back( string() );
}
string str = TCP1.receive(i);
if(str.length() > 0){
storeText[i] = str;
}
char buffer[10];
if (str.length()>0) {
for (int j=0; j<10; j++) {
buffer[j] = str[j];
}
}
cout << str << endl;
}
any idea where might go wrong? it used to run okay without that error when I first finished my app for quite a while.