Websockets + begin_request

49 views
Skip to first unread message

Massimo Callegari

unread,
Sep 21, 2013, 7:39:33 AM9/21/13
to mongoos...@googlegroups.com
Hello mongoose users !
First of all thank you for this great piece of software !

I'm trying to use it into a Qt application. I need a super-light web server to dynamically generate web pages and communicate via websocket.

So I overridden these 3 callbacks:
    callbacks.begin_request = begin_request_handler;
    callbacks.websocket_ready = websocket_ready_handler;
    callbacks.websocket_data = websocket_data_handler;

begin_request_handler works great but when I try to open a websocket connection I'm not able to handle it, so I get a Javascript error.
Looking in the code I've seen it is possible to detect and handle a websocket request with these functions:

static int is_websocket_request(const struct mg_connection *conn)
static void handle_websocket_request(struct mg_connection *conn)

Problem is that they are not "public", so I cannot access them from my Qt application.
I can copy-paste the code into my Qt app, but I'm wondering if there's a proper way to handle websocket handshake when begin_request callback is set.

Thank you very much in advance !
Massimo

Sergey Lyubka

unread,
Sep 21, 2013, 5:09:18 PM9/21/13
to mongoose-users
Try returning 0 from begin_request() if request is websocket.. It signals mongoose that user
does not want to handle the request, and mongoose needs to continue with handling.


--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/groups/opt_out.

Massimo Callegari

unread,
Sep 23, 2013, 3:27:48 PM9/23/13
to mongoos...@googlegroups.com
That was it !
Thank you very much Sergey

Sergey Lyubka

unread,
Sep 23, 2013, 3:31:26 PM9/23/13
to mongoose-users
You're welcome Massimo.
Let me know if you have any more questions.
Reply all
Reply to author
Forward
0 new messages