[Libwebsockets] Your thoughts on how to implement the following please.
andy at warmcat.com
Fri Apr 13 10:40:41 CEST 2018
On 04/13/2018 04:27 PM, Mooki Moo wrote:
> Hello List,
> I hope this isn't cheeky for my first post but I was wondering if the
> list readers might be able to help me here and point me in the right
> direction for my development. I am writing a WSS (only) Server using
> this library and I confess to not knowing very much about it, as this
> is the first time I have used it, but what I want to do is the
> When a user connects (via Web Browser) I need to provide them with
> their own database class, this class supports the usual CRUD
> operations for the user but it also has in it an async notification
> listener that listens on a user specific channel, with the channel
> determined at login.
> When data arrives on this channel I want to pass it to the WSS Client
> (User) it is intended for with minimal overhead. Some of the users
> will have limited traffic while others maybe getting notifications <1s
> so I don’t want to choke the system.
Lws approach is you get a callback when you can write something on a
connection. You generate what you want to write then. So you don't
fill up the user memory or the connection kernel buffers with data that
cannot be passed to the sink immediately.
> Although I don’t really know how to do it I can’t help but think that
> the best way to achieve this is to give each connected client their
> own protocol handler (or is that a vhost?) but is this possible? If it
> is are there any examples available on how I can implement this.
No... both vhosts and protocol handlers are implementations for
containing multiple connections that want the same thing. So you never
have one of those per connection.
You have a protocol handler per ws subprotocol you are creating
(probably one) and a vhost per different server you want to present
Take a look at /minimal-examples on master
> FWIW the number of concurrent users will be under 50.
> I’m building and running on Linux (4.15.15.-1 ARCH) using
> libwebsockets v2.4.2 with no libuv support (but I can change this)
> g++ 7.3.1
You don't need to use libuv. But if you are mainly serving, lwsws +
protocol plugins can be an effective way of avoiding building and
maintaining a "server": you just build and maintain your protocol
plugin. That wants libuv.
You should also better use master IMHO since that has the minimal examples.
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
More information about the Libwebsockets