-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lift restriction to use JSON for communication #20
Comments
I don't know a huge amount about how websockets are used in practice. I've done a few things in production with them - chat clients/servers, interactive websites, etc. However, in many of those cases we used something like Socket.io which use JSON across the wire. It was my assumption that using JSON across the wire is pretty typical. But, I could be wrong? So, feel free to correct me. Regarding your questions, you can actually use whatever format you want. You just need to make your own handler. Basically, make a subclass and overload https://github.com/socketry/async-websocket/blob/master/lib/async/websocket/connection.rb#L73-L79 Then on the client and/or server, specify the connection class as the handler: https://github.com/socketry/async-websocket/blob/master/lib/async/websocket/client.rb#L89 https://github.com/socketry/async-websocket/blob/master/lib/async/websocket/server.rb#L31 We should probably write some more documentation for this. The point of the handler is not just to be serialization, but any specific per-connection state you want to manage. Let me know if that's enough for you to start with. I don't have any specific examples, but it would be great to add some! |
Also agreed on using msgpack! It's great! |
To be fair, I haven't worked a lot with WebSockets in production settings outside of ActionCable. 🙂
Ah! I missed the fact that the handler can be injected.
This makes perfect sense to me. I think knowing that the handler can be injected, I'm against my own idea of merely configuring the format, in favour of the higher level abstraction. 🙂
This definitely points me in the right direction. I can open a PR to add some examples to the Thanks, @ioquatix! |
Hello, @ioquatix!
Firstly, thanks for all your work on the
async
project. I am very excited to see progress in these areas of the Ruby ecosystem. ❤️Now for my question. I was playing around with
async-websocket
over the weekend, and the first experiment resulted in an error, because the message I sent to the websocket server (just a single word) failed to parse as JSON.Is the restriction to send and receive JSON intentional? If so, maybe it should be documented down in the
README
. If not, I would be open to help add configuration options for other formats like plain text, MessagePack, etc.What do you think?
The text was updated successfully, but these errors were encountered: