warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.73k stars 1.48k forks source link

Question : TCP reuse for multiple wsi #2724

Closed snaami closed 2 years ago

snaami commented 2 years ago

Hello,

Simple question :

Is it possible to keep the TCP session alive after calling lws_wsi_close(wsi, LWS_TO_KILL_ASYNC);?

I have a scenario where the server require authentication to be used, so my client must resend the same message again with auth info in the headers, to do that I just close the current wsi and then in the close callback I schedule a new call tolws_client_connect_via_info(lws_connect_info) where I can add auth and some custom headers. This approach works very well but the protocol I'm trying to use has a requirement that the TCP should not get closed in this case and the same TCP session must be reused it's a (cwmp tr69 protocol) but by doing this the TCP is closed and a new TCP session is started.

lws-team commented 2 years ago

Depends...

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-client.h#n59-65

snaami commented 2 years ago

Hello, thank you for the answer, I'm already using PIPELINE flags, and it's working when the server return a 200 OK code, but if the server return code is http 401 the TCP is closed and a new one is opened the next lws_client_connect_via_info(lws_connect_info).

snaami commented 2 years ago

Note : I'm using lws 4.2.0

lws-team commented 2 years ago

Http/2 separates the tcp connection lifetime from the fate of an individual transaction more clearly and should be ok with that. h1 pipelining requires, eg, something consume the 401 body even if it doesn't care and is basically a hack in the protocol.

snaami commented 2 years ago

Yes I have http1 being used here , I cant use http2 restriction of the cwmp protocol .Tank you for the explanation