Reputation: 3551
I would like to connect to a WebSocket via Julia. I attempted to get an echo response from wss://echo.websocket.org
, but it does not seem to respond as I would have expected it to. Interestingly, it does seem to connect, though, whereas an invalid address will not.
julia> client = connect("echo.websocket.org", 443)
TCPSocket(open, 0 bytes waiting)
julia> println(client, "Hello, world!")
julia> readline(client)
""
Is it possible to accomplish this?
Upvotes: 4
Views: 1866
Reputation: 2779
There is now a specific library https://github.com/JuliaWeb/WebSockets.jl. Examples of how to use it are provided in examples/chat.jl and examples/chat-client.html.
Upvotes: 3
Reputation: 2097
Web socket clients cannot be implemented by opening a socket and reading and writing directly to it. There is a reasonably complicated protocol that needs to be implemented. Further, a websocket client is meant to receive push request, and hence needs some way to handle them asynchronously.
There is a websocket client library implemented in Julia: https://github.com/dandeliondeathray/DandelionWebSockets.jl
To install it, do: Pkg.clone("https://github.com/dandeliondeathray/DandelionWebSockets.jl")
To use it involves defining event handlers for network events. Please see here for an example using echo: https://github.com/dandeliondeathray/DandelionWebSockets.jl/blob/b23307f360ef0b62e3064c6b1484599eb660f63f/examples/echo.jl
Upvotes: 2