Genie.jl
Genie.jl copied to clipboard
Examples for web-socket architecture in Genie
Hello all,
So I have started a project in which I would like to process data from hardware devices in Julia, and then stream this data over web-socket to a React JS webpage. I am fairly new to web-sockets in general so I may be heading down the wrong path here, but is Genie capable of setting up channels for this? Or would I need my web app to be running the Genie framework as well?
Any assistance or examples of a similar system would be much appreciated
Cheers
Genie's webchannels set up web sockets communication between server and client. On the server you can define channels (routes for websockets traffic) and handle the requests. The WebChannels module provides the API to register clients and push data. On the client you can manage the server pushed data and the data pushes yourself - but if you include Genie's client JS files it will be easier to set up the communication.
I suggest taking a look at the docs and see if that helps: https://genieframework.github.io/Genie.jl/dev/tutorials/17--Working_with_Web_Sockets.html#Working-with-Web-Sockets
If I understand what marko's wanted correctly I think I just struggled with the sort of thing they're describing here
With an architecture like:
External Microservice -> Data pushed to Genie Webserver -> Genie WebServer -> Data pushed to client
I spent a lot time trying to get the 3rd external service to talk to the genie websocket server, but ultimately it looks like the correct way (or possibly only way?) to handle this is to just spin another websocket server for talking to external services and to only try to use the channel mechanism with genie clients.
e.g.
using HTTP.WebSockets
wsserver = WebSockets.listen!("127.0.0.1", ws_port) do ws
for msg in
# Do something with msg
end
end
If I'm mistaken I'd love to hear how to get it working such that only 1 websocket server is required, if my understanding is correct though I'd suggest making the documentation more clear about when NOT to try and use the channel routes since all the web socket documentation seems to assume that you want a web socket connection between Server/Client which is not always the case, and the underlying logic is abstracted enough that it can be difficult to figure out why its not working
(One might expect Router.channel("/foo/bar") to simply be creating a listener for ws://localhost:8000/foo/bar which would be trivial to push external events to, but this is in fact not the case)