Using WebSockets
WebSocket (ws://URL
), or wss://URL
for WebSocket Secure, is a bidirectional, low-latency, and high-speed protocol that builds on the TCP protocol. It uses HTTP(S) to make the connections (using ports 80
and 443
, respectively), so it also needs the HTTP
package. In a way, it combines characteristics of both UDP and TCP; it is message-based like UDP but also reliable and stateful like TCP. Chat services are among the most popular applications of WebSockets.
You can read data from or write data to a WebSocket, send ping or pong messages, and close the connection.
The WebSockets
package can be found at https://github.com/JuliaWeb/WebSockets.jl, which contains a complete example of the chat service.
To start using the WebSockets
package, add it via the REPL’s package mode:
(@v1.8) pkg> add WebSockets
The preceding command installs dependent packages such as URIs and HTTP and then precompiles them.
To set up a WebSocket, you need a URL and a...