[Libwebsockets] help regarding Built-in service loop entry loop.
andy at warmcat.com
Thu Nov 21 12:54:25 CET 2019
On 11/21/19 11:46 AM, 이성훈(Sunghoon Lee) wrote:
> My name is Alex Lee.
> Current my streaming server is using direct Linux socket API such as
> (socket, bind, listen, poll, accept, read/write)
> My streaming server receives connection request from several clients and
> send streaming data back to those requested clients.
> The streaming server normally does below routine.
> 1)socket(AF_UNIX, SOCK_STREAM, 0); (Create a server socket)
> 2)bind(serverSocket, (struct sockaddr*), .)
> 6)read()/write() for the accept client connections
> I'd like to convert above routines using build-in service loop entry
> provided in libwebsocket.
> I've read some of libwebsocket's API usage documents and ran examples in
> my Ubuntu machine.
> I'd like to get a confirmation before I start migration to libwebsocket
> whether my approach is correct or not.
> I'd like to use lws's internal built-in service loop entry.
> What I'll do is as below.
> 1.I'll make static struct lws_protocols protocols which has
> my_callback_http as an lws_context_creation_info's protocols field.
> 2.I'll *NOT* call any linux socket related APIs such as socket, bind,
> listen, poll, accept, read, write directly.
> Instead, I'll just let lws_service api handle all socket related
> functionalities just like many examples do and will receive event and
> data through my_callback_http registered in context.
Yes lws wraps all of that so you don't have to care any more at that
level. It wraps tls and does the http stuff as well.
> 3.I believe that my_callback_http will get called for client connections
> and receive requests from clients.
> Then I'll send binary streaming data using lws_write instead of using
> socket API such as accept, read, write and etc.
> 4.I am not thinking to use LWS_WITH_EXTERNAL_POLL because I am not
> running another sever.
> Please confirm if my approach above is correct.
> If wrong, please correct me.
Sounds right... the best guide is the related minimal examples like
minimal-http-server-tls and so, these will scale up to a lot of clients.
Depending on what you want to do you should also look at other related
examples like minimal-http-server-dynamic.
Basically confirm it works and then cut-and-paste the nearest example
and use that as the starting point, they are licensed public domain so
you can literally just copy them to get started.
> Thank you for guide and the help!.
> Best Regards,
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
More information about the Libwebsockets