Closed programarivm closed 1 month ago
Please, could you show the output of docker stats
, it's more informative about the server usage.
Another option is use SSE instead of Websockets. Websocket it's ideal for a multiplayer shooting game, the browser could be continuously streaming the player’s position, while simultaneously receiving updates on the location of all the other players from the server.
But with a chess game it is not necessary.
The Server Send Events (SSE) protocol is very simple and a better option. Almost it's a good start to discussion (talk) to understand it.
In reality Websockets are more vulnerable and heavier on resources. WebSocket connections are not protected by the same-origin policy. This makes them vulnerable to Cross-Site WebSocket Hijacking.
Other drawbacks:
Of course, SSE is a realtime push protocol, that stream the data continuously. I don't know witch server app you used for the SSE.
Perhaps, you used a PHP SSE with php-fpm, that it isn't event driven and for that need to send the data every x time. But Workerman is event driven, as soon as the SSE receive the event it's send to the browser.
PHP Chess Server is an asynchronous PHP server that provides functionality to play chess online over a WebSocket connection allowing support for multiple async PHP frameworks, with the default one being Workerman.
See:
Let's do this by your powers combined!
@walkor @clue @bwoebi
You can also support multiple SSE backends.
Ratchet use ReactPHP, and ReactPHP have SSE https://github.com/clue/php-sse-react
Workerman SSE https://manual.workerman.net/doc/en/http/SSE.html
I did'n find the SSE protocol in AMPHP, but it's very simple to implement.
And apart from PHP, we can use any SSE server from any language transparently from PHP.
I created the Workerman vmstats using SSE instead of Websockets, and the code in the backend and more in the frontend is simplified and with less lines.
https://github.com/walkor/workerman-vmstat
Suppose an application has features like Chat, Notification and Activity feeds.
SSE is the best option for that situations.
I only give another option, that can simplify the code work. But the decision is of @programarivm .
Also the SSE option is very good to other people watch the games realtime from other people.
SSE was not used, because IE and Edge didn't support it till 2020, ten years later than the others browsers. Even when exist pollyfills for this easy protocol.
Another problem was that with http 1.1, the browsers limit to 6 connections to the same server. But now with http 2 and http3 is not a problem.
Websocket don't work with http2, use http1 and for any tab open need a new TCP connection to the server. Exist an RFC to use webscocket with http2, but I doubt that arrive to the browsers, because for http3 exist a new protocol WebTransport, that is better. https://caniuse.com/?search=webtransport
You can inspect all the Websocket traffic, and I think that it is OK that is readable.
They send the messages in binary format, that it isn't necessary for that app. Only extra work in server and client.
EDIT: an the rare thing is that all the time send messages, even without moving any piece or do anything !!
SSE only permit UTF8 text, for send binary they use base64-encoding.
PD: Send in binary format don't hide anything.
Extra work without advantages. It's the server who need to authorize the premium features by user.
PD: obfuscation was never a good security system.
Sorry I'm not here for Chessbase_com. And this issue is not also. If you ask for my services, you need to pay me first. Thank you.
The API endpoints in the chesslablab/chess-api repo are to be rewritten in the chesslablab/chess-server in the form of WebSocket commands. One of the main reasons behind this decision is the optimization of resources. The PHP Chess API has demonstrated to be not too efficient while hosted in an AWS t2.micro instance along with Chess Data.
This is too many Docker containers. So we're moving to a WebSocket architecture based on multiple connections as described at Multiple websocket connection vs single websocket connection when using django channels.
Let's stick with separation of concerns.
The former will specialize in database commands and the latter in game commands.
See:
Happy learning!