1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

docs: spell out how to set the default protocol when client doesnt give any

This commit is contained in:
Andy Green 2018-01-03 08:29:29 +08:00
parent f95f689146
commit 15820da8ba

View file

@ -229,6 +229,47 @@ still do it all in one thread / process context. If the need is less
architectural, you can also create RAW mode client and serving sockets; this
is how the lws plugin for the ssh server works.
@section anonprot Working without a protocol name
Websockets allows connections to negotiate without a protocol name...
in that case by default it will bind to the first protocol in your
vhost protocols[] array.
You can tell the vhost to use a different protocol by attaching a
pvo (per-vhost option) to the
```
/*
* this sets a per-vhost, per-protocol option name:value pair
* the effect is to set this protocol to be the default one for the vhost,
* ie, selected if no Protocol: header is sent with the ws upgrade.
*/
static const struct lws_protocol_vhost_options pvo_opt = {
NULL,
NULL,
"default",
"1"
};
static const struct lws_protocol_vhost_options pvo = {
NULL,
&pvo_opt,
"my-protocol",
""
};
...
context_info.pvo = &pvo;
...
```
Will select "my-protocol" from your protocol list (even if it came
in by plugin) as being the target of client connections that don't
specify a protocol.
@section closing Closing connections from the user side
When you want to close a connection, you do it by returning `-1` from a