Skip to content
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

Can't start the QHttpServer outside of main ? #43

Open
dmacattack opened this issue Jan 26, 2018 · 2 comments
Open

Can't start the QHttpServer outside of main ? #43

dmacattack opened this issue Jan 26, 2018 · 2 comments

Comments

@dmacattack
Copy link

I've been playing with this for too long.
Why can't I start the QHttpServer outside the main? Such as in a class?
I've tried passing in the app variable to the class too and no go.

int main(int argc, char *argv[])
{
  QCoreApplication app(argc, argv);
  MyClass *pClass = new MyClass();
  pClass->startHttpServer(&app);
...
}

What is happening here?

@ghost
Copy link

ghost commented Mar 17, 2018

Do you have find a solution? I'm facing the same issue too. The server seems to listen (i.e. isListening == true) but it doesn't actually answer to incoming connections.

It's quite odd to leave the code in the main.

@dmacattack
Copy link
Author

I ended up doing this, its not what i wanted, but it works

int main(int argc, char *argv[])
{
   QCoreApplication app(argc, argv);
    
   // create http server instance
   qhttp::server::QHttpServer httpServer(&app);
 
   // create your class & pass in the object reference
   MyClass *pClass = new MyClass();
   pClass->start(&httpServer);

   ... 
}

void MyClass::start(qhttp::server::QHttpServer *server)
{
   server->listen( PORT, [&](qhttp::server::QHttpRequest *req, qhttp::server::QHttpResponse *res)
   {
       // lambda ... handle as you see fit
   } );
}

I hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant