mongoose/docs/c-api/http.h/mg_connect_ws.md
Dmitry Frank 7bed7ff482 Docs are generated for Mongoose
Comments in headers are changed a bit: removed adoc-specific stuff,
markdown is used instead

PUBLISHED_FROM=9242cce85cc52a47a197d377e7e23804721a6bb5
2016-03-21 13:29:29 +01:00

1.1 KiB

title decl_name symbol_kind signature
mg_connect_ws() mg_connect_ws func struct mg_connection *mg_connect_ws(struct mg_mgr *mgr, mg_event_handler_t event_handler, const char *url, const char *protocol, const char *extra_headers);

Helper function that creates an outbound WebSocket connection.

url is a URL to connect to. It must be properly URL-encoded, e.g. have no spaces, etc. By default, mg_connect_ws() sends Connection and Host headers. extra_headers is an extra HTTP headers to send, e.g. "User-Agent: my-app\r\n". If protocol is not NULL, then a Sec-WebSocket-Protocol header is sent.

Examples:

  nc1 = mg_connect_ws(mgr, ev_handler_1, "ws://echo.websocket.org", NULL,
                      NULL);
  nc2 = mg_connect_ws(mgr, ev_handler_1, "wss://echo.websocket.org", NULL,
                      NULL);
  nc3 = mg_connect_ws(mgr, ev_handler_1, "ws://api.cesanta.com",
                      "clubby.cesanta.com", NULL);