Comments (4)
It is probably about "Connection Timeout". It is waiting for timeout when there is no server to reach.
I have added tcpSocket.setTimeout(secs)
method and pushed today. (537d4d4)
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(...);
from async-sockets-cpp.
Hi, did you remove the getline()
above the loop?
string input;
getline(cin, input); // <---------------------- This blocks before entering the while loop.
while (input != "exit")
{
tcpSocket.Send(input);
getline(cin, input);
}
from async-sockets-cpp.
oops. my bad...
but it still happens in my code.
I have a timer that timer runs once every second. in the callback of the timer I'm trying to connect to the server each time.
when the connection succeeds - a message is printed and the timer is canceled. if it fails to connect to the server a message should be printed and another connection attempt should occur when the timer is being fired.
to verify that the program hangs, I created a second timer that runs every seconds and only prints the following message:
"another callback"
I have added a print in the beginning of the connecting timer callback, the prints "callback" and the current unix time in seconds.
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:
callback 1613910931
failed to connect to server : error 110 : Connection failed to the host.
callback 1613911061
failed to connect to server : error 110 : Connection failed to the host.
callback 1613911192
failed to connect to server : error 110 : Connection failed to the host.
callback 1613911323
failed to connect to server : error 110 : Connection failed to the host.
callback 1613911454
failed to connect to server : error 110 : Connection failed to the host.
callback 1613911586
failed to connect to server : error 110 : Connection failed to the host.
callback 1613911717
it always hangs for 131 seconds (ish) and the callback of the second timer is never being called.
If i remove the part of the connection from the callback, it runs as it should and prints the "callback" message every second and "another callback" is printed every 2 seconds.
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!
from async-sockets-cpp.
It looks like the problem is solved! thanks a lot!
from async-sockets-cpp.
Related Issues (20)
- nice api
- tcpsocket in tcpserver question HOT 1
- Don't use strings for error notifications HOT 2
- Installation under debian HOT 4
- Not accepting connections HOT 4
- TCP socket closed after 5 seconds HOT 3
- TCP server stops receiving packets after around 160 seconds HOT 2
- Installation under MacOS HOT 3
- memory leak in `TCPServer ::Accept` ? HOT 1
- client crashed when server is closed HOT 2
- Data race HOT 2
- memory leak HOT 3
- non-static const is causing problems HOT 9
- internal buffers are not configurable
- add func for tcpserver.hpp so that it can send msg to specific ip:port or send to all connected devices at once HOT 1
- Stack buffer overflow in static void Receive(TCPSocket* socket) at tcpsocket.hpp HOT 3
- Stack Buffer Overflow in static void ReceiveFrom(UDPSocket* udpSocket) at udpsocket.hpp HOT 5
- Add QNX support
- tcpserver close and exit, run it again is show 98 : Cannot bind the socket. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-sockets-cpp.