Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    An Tao
    @an-tao
    The sleep_for statement is useless and harmful for your program, why do you use it here?
    EMHussain
    @EMHussain

    The sleep_for statement is useless and harmful for your program, why do you use it here?

    To add delay after each request sleep_for statement is used.

    An Tao
    @an-tao
    we don't need any delay in an async program
    if you want the request be sent after 4 seconds, use timer instead.
    Seyyed Hossein Hasanpour
    @Coderx7
    Hi everyone.
    I'm new to drogon (actually I'm coming from cpprestsdk), is there any example for restful server/client for drogon?
    Martin Chang
    @marty1885
    @EMHussain Do you have GCC11 or MSVC 19 available? I recommend using coroutines. They make the control flow a lot easier.
    EMHussain
    @EMHussain

    we don't need any delay in an async program

    it is just an example of course it need to be improved and timers are is a good choice on sleep_for

    @EMHussain Do you have GCC11 or MSVC 19 available? I recommend using coroutines. They make the control flow a lot easier.

    Yes i have I can start with coroutines. Thanks for suggestion.

    Martin Chang
    @marty1885

    Hi everyone.
    I'm new to drogon (actually I'm coming from cpprestsdk), is there any example for restful server/client for drogon?

    The basics should the same. Every thing boils down to GET/POST/etc.. requests, dealing with content type and the semantics used by different frameworks.
    You can find how to to handles POST request in the login example. Then should be easy to figure out how stuff works just by looking at the API.

    The HttpController section in the docs should also help.
    Let us know if we can help.

    it is just an example of course it need to be improved and timers are is a good choice on sleep_for

    sleep_for blocks the thread from execution. If you're running the event loop and the client on the same thread. That blocks your client from doing anything.

    EMHussain
    @EMHussain
    Yes you're right i will sort it.
    Martin Chang
    @marty1885
    example:
    #include <drogon/drogon.h>
    #include <trantor/net/EventLoopThread.h>
    using namespace drogon;
    
    Task<> send_requests(trantor::EventLoop* loop) {
        HttpClientPtr client = HttpClient::newHttpClient("http://example.com", loop);
        auto req = HttpRequest::newHttpRequest();
        req->setPath("/");
        for(int i=0;i<10;i++) {
            auto resp = co_await client->sendRequestCoro(req);
            LOG_INFO << resp->body().size();
            co_await sleepCoro(loop, 10);
        }
    }
    
    int main() {
        trantor::EventLoopThread thr;
        thr.run();
        sync_wait(send_requests(thr.getLoop()));
    
        // Or
        //app().queueInLoop([]() { sync_wait(send_requests(app().getLoop()));});
        //app().run();
    }
    EMHussain
    @EMHussain
    @marty1885 Thanks for a nice example :)
    Seyyed Hossein Hasanpour
    @Coderx7
    @marty1885 Thanks a lot. really appreciate it. I'll have a look and in case I have more questions I'd ask here.
    Martin Chang
    @marty1885
    @Coderx7 BTW, CSP (views) are magically registered to the app by CMake and compilation tricks. There's no deceleration needed. Just in case you're wondering.
    EMHussain
    @EMHussain
    sendRequest for not working as
    for url one i.e abc.com works fine and another url i.e xyz.com segmentation fault. I am unable to what is happening here.
    My code.
    performRequest(url)
    {
        auto client = HttpClient::newHttpClient(url);
        auto req = HttpRequest::newHttpRequest();
        req->setMethod(drogon::Get);
        client->sendRequest(
                req, [](ReqResult result, const HttpResponsePtr &response)
                {
                    std::cout << "receive response  !"  <<std::endl;
                    std::cout << "receive response status !" <<response->getStatusCode() <<std::endl;  // segmentation fault here
                });
    }
    
    int main() {
    
        performRequest("abc.com"); // works fine
        performRequest("xyz.com"); // segmentation fault
        performRequest("abc.com"); // works fine
    
        return 0;
    }
    Martin Chang
    @marty1885
    1. There's no app().run(), nor you have manually spawned a event loop.
    2. Didn't specify the protocol (http/https)
    If you are after a easy to read/write API, use coroutines or the synchronous interface.
    Martin Chang
    @marty1885
    void performRequest(std::string url)
    {
        auto client = HttpClient::newHttpClient(url);
        auto req = HttpRequest::newHttpRequest();
        req->setMethod(drogon::Get);
        client->sendRequest(req, [](ReqResult result, const HttpResponsePtr &response)
        {
            std::cout << "receive response  !"  <<std::endl;
            std::cout << "receive response status !" <<response->getStatusCode() <<std::endl; 
        });
    }
    
    int main() {
    
        performRequest("http://abc.com"); 
        performRequest("http://xyz.com"); 
        performRequest("http://abc.com");
    
        app().run();
    }
    EMHussain
    @EMHussain
    Yes ofcourse app.run() is exist in main just did not show in example below lines. But my question is about client seg fault
    Yes coroutines is better choice and i am using your prevoius example was helpful for me :)
    Martin Chang
    @marty1885
    Your example doesn't crash for me. Even with debug mode and ASan turned on.
    EMHussain
    @EMHussain

    Your example doesn't crash for me. Even with debug mode and ASan turned on.

    it crashed on a particular one website https protocol but same website works with curl client i don't know what is the problem with drogon client. website link shared in private message.

    Martin Chang
    @marty1885
    I'll look into it later. BTW, are you using the latest source (or at least 1.6?)
    We had a TLS fix a while back that fixes TLS handshake failing
    EMHussain
    @EMHussain
    I using an older version 1.1.0
    Martin Chang
    @marty1885
    That's the problem. Please update to 1.6
    Old versions does not support SNI (Serice Name Indication). Some sites requires SNI to function.
    Aayush-2492
    @Aayush-2492
    is there a difference in using app().registerHandler() for a particular route and using controller?
    Martin Chang
    @marty1885
    No. internally they are handled in the same way.
    Aayush-2492
    @Aayush-2492
    When i use the create model command, it gives an error "Drogon does not support PostgreSQL, please install PostgreSQL development environment before installing drogon." Postgres is already installed on my computer and works fine. Then why this error?
    An Tao
    @an-tao
    did you install the libpq library for development?
    Martin Chang
    @marty1885:matrix.org
    [m]
    You didn't build Drogon with PostgreSQL support enabled. Most likely you didn't install libpq-dev (or the equivalent package on you distro). Or the package wasn't available when building Drogon.
    Aayush-2492
    @Aayush-2492
    @an-tao i used the brew command to install postgresql as mentioned in the installation part in documentation. I didnt install libpq separately
    @marty1885:matrix.org I think I installed it after building drogon. So i have to reinstall drogon?
    An Tao
    @an-tao
    try to remove the build folder, and rebuild drogon again
    Aayush-2492
    @Aayush-2492
    It worked!! Thanks for the quick response
    Rafał Bugajewski
    @rbugajewski
    The current Dockerfile builds Drogon as-is. How would I use this file to create a container with a custom Drogon site?
    Because to me it looks like I can reuse the dependencies from either Arch or Ubuntu, but then check out my own repository etc. It doesn’t look like the Dockerfile would be well suited for creating custom Drogon instances, or am I missing something?
    An Tao
    @an-tao
    Use it as a base to create your own application docker images.
    Rafał Bugajewski
    @rbugajewski
    👍
    Martin Chang
    @marty1885
    Thinking about it. Is there a elegant way to deploy drogon websites? My solution is more old school.
    I build a package for the system's package manager. The launch it through the init system.
    evanp456
    @evanp456_gitlab
    Hi All, What IDE are you using for development in C++ in Mac or Linux?
    Martin Chang
    @marty1885:matrix.org
    [m]
    I use VSCode and VIM. Sometimes CLion
    evanp456
    @evanp456_gitlab
    Thanks Martin.
    Aayush-2492
    @Aayush-2492
    I am new to websocket programming. I saw the documentation of websocket controller of drogon and the example on github and got confused. There were two kinds of pointers WebSocketClientPtr and WebSocketConnectionPtr. How are they both used? If someone could explain in words (codewise)how websocket is used to send messages it would be helpful
    An Tao
    @an-tao
    WebSocketConnectionPtr represents connections on server or client, you could use it send messages. WebSocketClientPtr represents the websocket client, usually it contains an available WebSocketConnectionPtr object.
    9 replies