centrifugal / centrifuge-swift

Swift client SDK for bidirectional real-time communication with Centrifugo and Centrifuge-based server over WebSocket
MIT License
49 stars 44 forks source link

I received error #75

Closed Sargis closed 2 years ago

Sargis commented 2 years ago

func onError( client: CentrifugeClient, event: CentrifugeErrorEvent){

}

about onError function, I get following error

▿ CentrifugeError ▿ transportError : 1 element ▿ error : WSError

Please help me try to understand error: Thanks

FZambia commented 2 years ago

Hello, do you know when it happens? On connect? In general, the simplest way is to look at server logs and logs should contain entry on INFO level about the reason of client's bad request.

Most often you can get error like this during connect if you have invalid token, or connecting without token and without connect proxy configured on server side.

Sargis commented 2 years ago

Thanks for response I get following logs from backend side

{"level":"info","client":"ce6b4c25-7694-4b1a-8fe5-5f2266ebc15d","data":"n\b\u0015\"j\naeyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyNiJ9.qDnjxWXiYhViUWCG3yLVFFSaEreKicVSjCGU-QVa2M0\"\u0005swift","error":"invalid character '\b' in literal null (expecting 'u')","user":"","time":"2022-11-24T12:16:17Z","message":"error decoding command"} {"level":"debug","client":"ce6b4c25-7694-4b1a-8fe5-5f2266ebc15d","reason":"bad request","reconnect":false,"user":"","time":"2022-11-24T12:16:17Z","message":"closing client connection"}

FZambia commented 2 years ago

Probably you have a proxy between app and Centrifugo which does not allow Sec-WebSocket-Protocol header to pass so Centrifugo does not receive subprotocol and thinks it's a client connecting over JSON protocol. To test this idea you may try to add ?cf_protocol=protobuf to WebSocket URL.

If it does not help you can provide detailed steps to reproduce + exact client and server versions so I could look at this myself, otherwise I can only guess what's going on.

Sargis commented 2 years ago

Hello We have updated server version, and everything is work perfectly

Thank you very much Alexander

FZambia commented 2 years ago

Ah, cool :) Welcome!