Skip to content
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

No :socket key in websocket server object #139

Closed
mkskitka opened this issue Aug 5, 2021 · 3 comments
Closed

No :socket key in websocket server object #139

mkskitka opened this issue Aug 5, 2021 · 3 comments

Comments

@mkskitka
Copy link

mkskitka commented Aug 5, 2021

Hi,

I am creating a websocket server using the example provided in the README. The service dictionary send to the websocket_example function does not contain a key :socket. The socket is being created I can see it running on my system processes but I am not able to access it to read and write.

MK

@mkskitka
Copy link
Author

mkskitka commented Aug 5, 2021

Code:

using Mux
using JSON

function websocket_service(x)
# No key :socket found in x !
println(x)
sock = x[:socket]
while !eof(sock)
str = String(read(sock))
println("Received data: " * str)
json = JSON.parse(str)
# Call to POWERED II Model with Json Observations
write(sock, "Here are the predictions" * str)
end
end

WebSocket server

@app w = (
Mux.wdefaults,
route("/ws_io", websocket_service),
Mux.wclose,
Mux.notfound());

# Serve both servers on the same port.

wait(serve(w, 8000))

@mkskitka
Copy link
Author

mkskitka commented Aug 5, 2021

Ok I got it workings. Turns out the Websocket server isn't a standalone service, you also need the HTTP server to host the socket!

@cmcaine
Copy link
Collaborator

cmcaine commented Aug 11, 2021

Great!

The README.md contains a complete example of how to do this, but I suppose it could be clearer that Mux (WebSockets.jl) expect a regular HTTP server and a WS server.

Please feel free to make a PR changing the README if you think it helps :)

@cmcaine cmcaine closed this as completed Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants