-
Notifications
You must be signed in to change notification settings - Fork 72
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
program blocked when tcp client connection to a tcp server failed #15
Comments
Hi, did you remove the string input;
getline(cin, input); // <---------------------- This blocks before entering the while loop.
while (input != "exit")
{
tcpSocket.Send(input);
getline(cin, input);
} |
oops. my bad... but it still happens in my code. this is the code inside the timer's callback: std::cout.setf(std::ios::fixed);
std::cout << "callback " << std::setprecision(0) << base_node_->now().seconds() << std::endl;;
command_client_.Connect(cell_address_, command_client_port_, [&] {
std::cout << "Connected to cell " << name_ << " server successfully." << std::endl;
connecting_timer_->cancel();
},
[&](int errorCode, const std::string &errorMessage) {
// CONNECTION FAILED
std::cout << "failed to connect to server : error " <<
std::to_string(errorCode) << " : " << errorMessage << std::endl;
});
the output is:
it always hangs for 131 seconds (ish) and the callback of the second timer is never being called. when there is listening server - every thing is OK. when I run it in debug mode it's clear the it hangs inside the Connect function. again, thanks for the hard work! |
It is probably about "Connection Timeout". It is waiting for timeout when there is no server to reach. I have added Can you pull the project and try it again with setting a timeout value? Example: // Set timeout seconds:
tcpSocket.setTimeout(1);
// Then try to connect:
tcpSocket.Connect(...); |
It looks like the problem is solved! thanks a lot! |
Hi.
first of all - great work. the library is easy to use and understand.
When i try to connect to a tcp server that does not exist, the program get stuck after "Connection failed to the host" message is printed.
to reproduce that I ran the tcp-client.cpp example, I added print inside the while loop. It never gets printed.
The text was updated successfully, but these errors were encountered: