centrifugal / centrifugo

Scalable real-time messaging server in a language-agnostic way. Self-hosted alternative to Pubnub, Pusher, Ably. Set up once and forever.
https://centrifugal.dev
Apache License 2.0
8.45k stars 598 forks source link

Unable To Connect With anonymous mode #782

Closed alouani-youssef closed 8 months ago

alouani-youssef commented 8 months ago

When I try to connect to the Centrifugo server using webSocket client

I got the following Error : {"level":"info","client":"a4c0189c-ba87-4a0f-91c8-3e3631a87671","command":"id:151","reason":"bad request","user":"","time":"2024-03-06T16:51:22Z","message":"disconnect after handling command"}. The Configuration file for the centrifugo server is:

 {
  "admin": false,
  "namespaces": [
    {
      "name": "interaction",
      "presence": true,
      "join_leave": true
    },
    {
      "name": "notifications"
    },
    {
      "name": "event"
    }
  ],
  "allowed_origins": [
    "*"
  ],
  "allow_subscribe_for_client": true,
  "allow_anonymous_connect_without_token": true
}

within postman, the client I use to try to connect I got: 3502 Error: stale

FZambia commented 8 months ago

Hello @alouani-youssef ,

Centrifugo has its own protocol, are you using our bidirectional SDK to connect? If yes - please share the code and also full server logs (I suggest enabling "log_level": "trace") - not only last log message.

alouani-youssef commented 8 months ago

Hello @FZambia Those are the logs after enabling the log_level trace, {"level":"debug","method":"GET","status":101,"path":"/connection/websocket","addr":"IP","duration":"269.45µs","time":"2024-03-07T11:02:10Z","message":"http request"} {"level":"trace","client":"e9b6aa27-c385-4cbb-b368-7d232d371570","command":"{\"id\":2}","user":"","time":"2024-03-07T11:02:10Z","message":"<--"} {"level":"info","client":"e9b6aa27-c385-4cbb-b368-7d232d371570","command":"id:2","reason":"bad request","user":"","time":"2024-03-07T11:02:10Z","message":"disconnect after handling command"} {"level":"debug","client":"e9b6aa27-c385-4cbb-b368-7d232d371570","duration":23.967399,"transport":"websocket","time":"2024-03-07T11:02:10Z","message":"client connection completed"} {"level":"debug","client":"e9b6aa27-c385-4cbb-b368-7d232d371570","reason":"bad request","user":"","time":"2024-03-07T11:02:10Z","message":"closing client connection"} {"level":"debug","method":"GET","status":101,"path":"/connection/websocket","addr":"IP","duration":"150.432µs","time":"2024-03-07T11:02:21Z","message":"http request"} {"level":"debug","client":"fd219032-aafe-4621-bf8f-d33026fdb219","transport":"websocket","time":"2024-03-07T11:02:21Z","message":"client connection established"} {"level":"trace","client":"fd219032-aafe-4621-bf8f-d33026fdb219","command":"{\"id\":94}","user":"","time":"2024-03-07T11:02:21Z","message":"<--"} {"level":"info","client":"fd219032-aafe-4621-bf8f-d33026fdb219","command":"id:94","reason":"bad request","user":"","time":"2024-03-07T11:02:21Z","message":"disconnect after handling command"} {"level":"debug","client":"fd219032-aafe-4621-bf8f-d33026fdb219","duration":49.836208,"transport":"websocket","time":"2024-03-07T11:02:21Z","message":"client connection completed"} {"level":"debug","client":"fd219032-aafe-4621-bf8f-d33026fdb219","reason":"bad request","user":"","time":"2024-03-07T11:02:21Z","message":"closing client connection"} {"level":"debug","method":"GET","status":101,"path":"/connection/websocket","addr":"IP","duration":"150.265µs","time":"2024-03-07T11:02:22Z","message":"http request"} {"level":"debug","client":"db7b311c-665e-4532-ac50-76d05f46777c","transport":"websocket","time":"2024-03-07T11:02:22Z","message":"client connection established"} {"level":"trace","client":"db7b311c-665e-4532-ac50-76d05f46777c","command":"{\"id\":3}","user":"","time":"2024-03-07T11:02:22Z","message":"<--"} {"level":"info","client":"db7b311c-665e-4532-ac50-76d05f46777c","command":"id:3","reason":"bad request","user":"","time":"2024-03-07T11:02:22Z","message":"disconnect after handling command"} {"level":"debug","client":"db7b311c-665e-4532-ac50-76d05f46777c","duration":40.359138,"transport":"websocket","time":"2024-03-07T11:02:22Z","message":"client connection completed"} {"level":"debug","client":"db7b311c-665e-4532-ac50-76d05f46777c","reason":"bad request","user":"","time":"2024-03-07T11:02:22Z","message":"closing client connection"} {"level":"debug","method":"GET","status":101,"path":"/connection/websocket","addr":"IP","duration":"87.581µs","time":"2024-03-07T11:02:23Z","message":"http request"} {"level":"debug","client":"0c9e3806-336a-4b6a-8368-6ceee41a563c","transport":"websocket","time":"2024-03-07T11:02:23Z","message":"client connection established"} {"level":"trace","client":"0c9e3806-336a-4b6a-8368-6ceee41a563c","command":"{\"id\":3}","user":"","time":"2024-03-07T11:02:23Z","message":"<--"} {"level":"info","client":"0c9e3806-336a-4b6a-8368-6ceee41a563c","command":"id:3","reason":"bad request","user":"","time":"2024-03-07T11:02:23Z","message":"disconnect after handling command"}

FZambia commented 8 months ago

You are sending wrong JSON commands, that's why connection is closed. You need to use our SDKs to communicate with Centrifugo or use proper command structure (described here). See also docs on how to use Postman when you want to debug sth.

FZambia commented 8 months ago

Closing, hope it helped. Join our community channels if you have any questions