I've recently heard about websockets that allows you to make interactive discord bot, or things like online chat, but this is a new concept to me and i'm not sure I fully understand how it works, and i'm having some trouble making my own websocket "daemon" server.
Most of the time when i search online, i find javascript(node.js) server framework, or php framework, but that's not what i'm looking for, I'd want to understand how it works with just php for now.
I found some functions on the php documentation, and with the specifications at https://tools.ietf.org/html/rfc6455 and came out with this code :
https://pastebin.com/YKj4dY3U
However, when i try connecting to it using my browser, it prints nothing the first time, and when i refresh, the server stop running.
https://pastebin.com/LqrwsCJC
I thought it was because my code only handle one client, but it's weird that it prints nothing on the log. Here's what the server prints before disconnecting
C:\wamp64\www\websockets>php ws.php
LISTENING...
INCOMING CONNECTION FROM 127.0.0.1 : Resource id #5
HTTP/1.1 101 Switching Protocols
Upgrade: Websocket
Connection: Upgrade
Sec-WebSocket-Accept: NDA1YmFhOGJiMzFkNmJhOThlNjcwOTE5MTc0Yjg2Mzg5Mjg5OWM4OA==
CLIENT CONNECTED SUCCESSFULLY
I know it would be "easier" to just use some php or js framework but I'd want to understand how it works and then later i'll use a framework to make the code cleaner/easier to write.
Thanks for your help !