[Libwebsockets] multiple clients with http body using http persistent connection (PIPELINE)

dev akira akira.pp.dev at gmail.com
Tue Jan 28 12:19:19 CET 2020


Hello,

I would like to make multi clients connect a server (with the same address
and port), sequentially with multiple paths and methods. I can implement
the code but every client setup it's own tcp connection (and tls tunnel).
Now, I would like to make a http persistent connection using a single tcp
connection (and a single tls tunnel).

I tried LCCSCF_PIPELINE but did not work when the clients has http body.
For example, when I make a http request with http body using
lws_client_connect_via_info(). This generates a wsi (1) and complets client
http. Then, make a second http with http body using
lws_client_connect_via_info(). This generates another wsi (2) but results
in "lws_callback_on_writable(): failed to find socket -1" and cannot make
the callback function called with LWS_CALLBACK_CLIENT_HTTP_WRITEABLE(57) to
send http body.

I searched libwebsockets docs, sample codes, mailinglist but cannot find it.
(Ref)
https://libwebsockets.org/pipermail/libwebsockets/2020-January/008229.html
https://libwebsockets.org/pipermail/libwebsockets/2018-August/003810.html
https://libwebsockets.org/pipermail/libwebsockets/2017-September/007318.html

Could you kindly let me know how to make 2nd client send http body using a
single tcp connection?




Below is the log when I made two clients to make http requests POST and GET
sequentically (I used Linux).
Here, I would like to use http/1.1 and tls.
--------------------------------------------------------
### Create a lws_context
<<< struct lws_context *context = lws_create_context( &info );>>>
...
### The 1st client connection request ###
<<< struct lws_client_connect_info ccinfo;                    >>>
<<< ccinfo.alpn = "http/1.1";                                 >>>
<<< ccinfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_PIPELINE; >>>
<<< ccinfo.address = "192.168.1.100"; ccinfo.port = "443"     >>>
<<< ccinfo.method = "POST"; ccinfo.path = (PATH1)             >>>
<<< lws_client_connect_via_info(&ccinfo)                      >>>
...
[2020/01/28 18:04:56:2962] I: lws_vhost_bind_wsi: vh default:
count_bound_wsi 1
[2020/01/28 18:04:56:2962] D: lws_role_transition: 0x7f66b4035c80: wsistate
0x10000200, ops h1
[2020/01/28 18:04:56:2962] I: lws_client_connect_via_info: role binding to
h1
[2020/01/28 18:04:56:2963] I: lws_client_connect_via_info: protocol binding
to http
...
[2020/01/28 18:04:56:2963] I: lws_client_connect_via_info: wsi
0x7f66b4035c80: h1 http entry  <-- This corresponds wsi (1)
...
****** reason=LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER(24) ******
<<< call lws_add_http_header_by_token()        in callback function
 >>>
<<< call lws_client_http_body_pending(wsi, 1)  in callback function
 >>>
<<< call lws_callback_on_writable(wsi, 0)      in callback function
 >>>
[2020/01/28 18:04:56:3044] I: lws_client_socket_service: HANDSHAKE2:
0x7f66b4035c80: sending headers on 0x7f66b4035c80 (wsistate 0x10000013
0x10000013), w sock 6, wsi sock 6
[2020/01/28 18:04:56:3044] D: body pending
...
****** reason=LWS_CALLBACK_CLIENT_HTTP_WRITEABLE(57) ******
<<< call lws_client_http_body_pending(wsi, 0)  in callback function
 >>>
...
****** reason=LWS_CALLBACK_COMPLETED_CLIENT_HTTP(47) ******
[2020/01/28 18:04:56:4791] I:
_lws_generic_transaction_completed_active_conn: nothing pipelined waiting
...
...
### The 2nd client connection request ###
<<< struct lws_client_connect_info ccinfo;                    >>>
<<< ccinfo.alpn = "http/1.1";                                 >>>
<<< ccinfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_PIPELINE; >>>
<<< ccinfo.address = "192.168.1.100"; ccinfo.port = "443"     >>>
<<< ccinfo.method = "GET"; ccinfo.path = (PATH2)              >>>      <--
method and path are different from the first one.
<<< lws_client_connect_via_info(&ccinfo)                      >>>
...
[2020/01/28 18:04:56:4793] I: lws_vhost_bind_wsi: vh default:
count_bound_wsi 2
[2020/01/28 18:04:56:4793] D: lws_role_transition: 0x7f66b4029050: wsistate
0x10000200, ops h1
[2020/01/28 18:04:56:4793] I: lws_client_connect_via_info: role binding to
h1
[2020/01/28 18:04:56:4793] I: lws_client_connect_via_info: protocol binding
to http
...
[2020/01/28 18:04:56:4794] I: lws_client_connect_via_info: wsi
0x7f66b4029050: h1 http entry  <-- This corresponds wsi (2)
...
****** reason=LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER(24) ******
<<< call lws_add_http_header_by_token()        in callback function
 >>>
<<< call lws_client_http_body_pending(wsi, 1)  in callback function
 >>>
<<< call lws_callback_on_writable(wsi, 0)      in callback function
 >>>
[2020/01/28 18:04:56:4797] D: lws_callback_on_writable: failed to find
socket -1
!!!
!!!
!!!  lws_callback_on_writable failed and callback never called with
reason=LWS_CALLBACK_CLIENT_HTTP_WRITEABLE(57) !!!
!!!
!!!
[2020/01/28 18:04:56:4797] I: lws_client_socket_service: HANDSHAKE2:
0x7f66b4029050: sending headers on 0x7f66b4035c80 (wsistate 0x10000013
0x10000011), w sock 6, wsi sock -1
[2020/01/28 18:04:56:4798] D: body pending
--------------------------------------------------------

Thank you,
Akira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200128/b2cde35c/attachment.htm>


More information about the Libwebsockets mailing list