Tinder / Scarlet

A Retrofit inspired WebSocket client for Kotlin, Java, and Android
Other
3.23k stars 237 forks source link

the request protocol is http not ws? #188

Open gzhhong opened 3 years ago

gzhhong commented 3 years ago

Hello all, the request interceptor print the log and shows that scarlet use http instead of ws to send request, and the server side return code 101, "switching protocols", how to fix? thanks.

solidogen commented 2 years ago

Http request is sent with following headers:

Connection: Upgrade
Upgrade: websocket

101 status means that handshake succeeded and protocol was switched to websocket, and two-way communication is ready. It just means everything is fine.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism

AlCappaccino commented 2 years ago

I am having the same issue, keep getting the same log and it seems like scarlet is connecting and reconnecting all the time. It is indeed not working

greggiacovelli commented 2 years ago

All connections will start with http(s) and then upgrade to ws(s). This is the specification as @solidogen has linked. What you are seeing is completely expected as far as the upgrade path.

Regarding the disconnects, if you are seeing constant disconnects that may need to be investigated, however common issues can include improper control frame timing expectations on the webserver and client. Whereas in order to maintain a live connection a series of messages have to be sent between the client and server (not necessarily within your application). https://datatracker.ietf.org/doc/html/rfc6455#section-5.5 specifically how control messages Ping and Pong relate.