Giter Club home page Giter Club logo

Comments (4)

eminfedar avatar eminfedar commented on June 25, 2024 1

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.

eminfedar avatar eminfedar commented on June 25, 2024

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.

roboticanyair avatar roboticanyair commented on June 25, 2024

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.

roboticanyair avatar roboticanyair commented on June 25, 2024

It looks like the problem is solved! thanks a lot!

from async-sockets-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.