First, a little bit of context: I use Crystal for a websocket daemon. For that, I use the WebSocket class but I don’t want to rely on the
#run function (I have my own loop). I store WebSocket instances and file descriptors that I use in a
select function (the one in the C standard library), since I also keep track of other sockets than the websocket’s ones.
(FYI, I extended the WebSocket class too, I did a
#read function which could be added in the upstream class if anyone’s interested.)
Now, the problem is that I have silent disconnections: TCP doesn’t send keep-alive messages, and no websocket ping is sent. At some point, my application doesn’t respond anymore, the socket seems closed. I don’t see any option to send periodic messages, or to use TCP keep-alive messages in the WebSocket class. What should I do?
Should I use the TCPSocket class and use the
#tcp_keepalive_idle function? This seems rather low-level, I’m not sure a web developer should have to dive into this to play with websockets.
Should I force ping messages (from the client or the server)?
Besides, since I don’t use the
#run function in the WebSocket class,
#on_message functions aren’t called. That’s not much of a problem, I could add another function to see if the received message is a ping, pong or a data message. But, before doing anything, I want to know if it’s necessary, or if I can just have standard, RFC-compliant, TCP keep-alive messages.
Thanks for your time.