[Libwebsockets] R: R: R: Unable to connect to the server with Android

Stefano Mora stefano.mora at newdep.com
Wed Apr 17 13:18:15 CEST 2019


I rebuilt the library starting from the scratch.

What happened was:
-> the app connects:
...
...
WSI_TOKEN_NAME_PART '
' 0x0A (role=0x20000000) wsi->lextable_pos=238
known hdr 8
v13 hdrs done
lws_handshake_server: parsed count 157
lws_handshake_server: lws_parse sees parsing complete
lws_select_vhost: vhost match to default based on port 7681
lwsi_set_state(0x564e816bb470, 0x20000209)
__lws_set_timeout: 0x564e816bb470: 0 secs (reason 0)
Upgrade to ws
lws_process_ws_upgrade: defaulting to prot handler 0
lws_ensure_user_space: 0x564e816bb470 protocol pss 0, user_space=(nil)
lws_role_transition: 0x564e816bb470: wsistate 0x20000117, ops ws
_realloc: size 200: ws struct
lws_ensure_user_space: 0x564e816bb470 protocol pss 0, user_space=(nil)
lws_parse calling handshake_04
lws_ensure_user_space: 0x564e816bb470 protocol pss 0, user_space=(nil)
issuing resp pkt 129 len
lws_issue_raw: ssl_capable_write (129) says 129
lwsi_set_state(0x564e816bb470, 0x20000117)
lwsi_set_state(0x564e816bb470, 0x20000117)
_realloc: size 4116: rx_ubuf
Allocating RX buffer 4112
ws established
accepted v13 connection
lws_process_ws_upgrade2: 0x564e816bb470: dropping ah on ws upgrade
__lws_header_table_detach: wsi 0x564e816bb470: ah 0x564e816c0fe0 (tsi=0, count = 1)
__lws_header_table_detach: nobody usable waiting
_lws_destroy_ah: freed ah 0x564e816c0fe0 : pool length 0
__lws_header_table_detach: wsi 0x564e816bb470: ah 0x564e816c0fe0 (tsi=0, count = 0)
lws_h1_server_socket_service: consumed 157
lws_read_h1: h1 path: wsi state 0x117
lws_parse_ws: received 33 byte packet
lws_ws_frame_rest_is_payload: using 27 of raw input (total 27 on offer)
lws_ws_rx_sm: ws fragment length exhausted
spill on http
lws_parse_ws: exit with 0 unused

--> The app thinks to be connected but the server is not in ESTABLISHED phase !!
--> Time passes ..

lws_read_h1: h1 path: wsi state 0x117
lws_parse_ws: received 6 byte packet
spill on http
received 0 byte ping, sending pong
_lws_change_pollfd: wsi 0x564e816bb470: fd 7 events 1 -> 5
lws_parse_ws: exit with 0 unused
issuing pong 0 on wsi 0x564e816bb470

--> Here the app/mobile went to standby so maybe it closed the connection.

lws_issue_raw: ssl_capable_write (2) says 2
_lws_change_pollfd: wsi 0x564e816bb470: fd 7 events 5 -> 1
lws_handle_POLLOUT_event: 0x564e816bb470: non mux: wsistate 0x20000117, ops ws
error on reading from skt : 104
rops_handle_POLLIN_ws: LWS_SSL_CAPABLE_ERROR
0x564e816bb470: Close and handled
__lws_close_free_wsi: 0x564e816bb470: caller: close_and_handled
__lws_close_free_wsi: shutdown conn: 0x564e816bb470 (sk 7, state 0x117)
closing: shutdown (state 0x117) ret 107
__lws_close_free_wsi: real just_kill_connection: 0x564e816bb470 (sockfd 7)
_lws_change_pollfd: wsi 0x564e816bb200: fd 6 events 1 -> 1
lwsi_set_state(0x564e816bb470, 0x2000001e)
__lws_close_free_wsi_final: wsi 0x564e816bb470: fd 7
lws_vhost_unbind_wsi: vh default: count_bound_wsi 1
__lws_free_wsi: 0x564e816bb470, remaining wsi 2



My doubt is: why the server did not enter in ESTABLISHED phase?



-----Messaggio originale-----
Da: Andy Green <andy at warmcat.com> 
Inviato: mercoledì 17 aprile 2019 11:06
A: Stefano Mora <stefano.mora at newdep.com>
Oggetto: Re: R: R: [Libwebsockets] Unable to connect to the server with Android



On 17/04/2019 16:52, Stefano Mora wrote:
> Andy,
> in the meantime I added a verbose log and I have the following:

It seems to make the connection fine.  Then some time afterwards, we are given a no-payload ws PING

> lws_read_h1: h1 path: wsi state 0x117
> lws_parse_ws: received 6 byte packet
> spill on http
> received 0 byte ping, sending pong
> _lws_change_pollfd: wsi 0x55f433ca1260: fd 7 events 1 -> 5
> lws_parse_ws: exit with 0 unused
> issuing pong 0 on wsi 0x55f433ca1260

We send the PONG, it also has to be zero payload

> lws_issue_raw: ssl_capable_write (2) says 2
> _lws_change_pollfd: wsi 0x55f433ca1260: fd 7 events 5 -> 1
> lws_handle_POLLOUT_event: 0x55f433ca1260: non mux: wsistate 
> 0x20000117, ops ws
> rops_handle_POLLIN_ws: zero length read

This either indicates the server sent us a zero-length packet, or that it hung up on us.

Unforunately recv() can't tell the difference.  See RETURN VALUE section

http://man7.org/linux/man-pages/man2/recv.2.html

-Andy


More information about the Libwebsockets mailing list