Rick
Rick

Reputation: 8846

How to open a connection to a WebSocket server in Crystal (use Crystal as client)

I would like to consume a websocket server connection using Crystal as a client. Does the Crystal standard library provide a WebSocket client library?

Upvotes: 3

Views: 1065

Answers (1)

Julien Portalier
Julien Portalier

Reputation: 2999

Starting with Crystal 0.8.0 you should be able to:

socket = HTTP::WebSocket.open("example.com", "/connect")
socket.send "action"
message = socket.receive

See https://github.com/manastech/crystal/pull/1369 for more details.

Upvotes: 3

Related Questions