Hi, I’m having some trouble with ofxTCPClient blocking my program while trying to connect to a server. I’m running a client.setup(string ip, int _port) function every 5 seconds to reconnect to the server if it’s not connected. When the server is not running (which i’m purposely testing for), the app pauses/blocks for quite a while and eventually timesout (191 ETIMEDOUT).
I thought it was non blocking by default, or does this only apply to the sending/receiving of messages? Maybe I’ll have to thread it?
Can you check to see if your app is hanging at the call to getpeername() inside ofxTCPManager::GetRemoteAddr()? You might want to check out threading your TCP interface, but it could be a little bit tricky.
How much did you thread? Only the setup or the whole communication?
I’m experiencing the same problem in IOS - app blocks and exits when the server is not connected to the network. Apparently the server software does not have to be running, but if no device is present at the specified ip it fails.
Hey Tom, yeah I threaded the whole tcp client. But you could probably just thread the setup/connecting part, because after it’s connected the client is already non blocking by default anyway.
i have the same issue here and i try to understand how to thread the connection. Do you have an example please ?
I think the best thing would be to thread the whole tcpClient connexion, but maybe just the connection can be ok as, like someone said, once it is connected everything is ok.
Can anyone provide some example of code for threading a tcp connection please ?
i had a look at your code.
you don’t seem to thread the whole connection process, do you ?
I’m working on a project with same goals : send messages to servers and read their answer.
I don’t manage servers, only client connections.
Is it better (easier ?) to thread only the connection trial (i.e. client.setup(host, port) ?
I have multiple methods like sendCommand(), updateStatus() etc… i don’t clearly understand how to implement them. Do i need a thread for every method ? because if i understand well, only one thread is possible (threadedFunction()) ?
PS : for instance, i don’t connect and then send command. Everything is included in the method. for exemple :
string sendCommand (string command) {
//try to connect
//if connected, send "command"
//read answer
//return answer
}
void updateStatus() {
// try to connect
// if connected, send query POWER
// update power status value
// send query ERROR
// update error status
etc ...
}
PS : And in all the examples i found concerning Threading, they write a threadedFunction() in a separate header file and call it with start() and stop() methods. I don’t see those in you code !