Calling websocket-rails from a ruby client

186 Views Asked by At

I have a pure ruby client where I want to send a message over a websocket connection. The websocket runs inside a rails application and I am using the websocket-rails gem ( https://github.com/websocket-rails/websocket-rails )

With the following code I am able to connect to my websocket successfully but I can not receive any messages.

require 'rubygems'
require 'websocket-client-simple'

ws = WebSocket::Client::Simple.connect 'ws://localhost:3000/websocket'

ws.on :message do |msg|
  puts msg.data
end

ws.on :open do
  ws.send 'hello!!!'
end

ws.on :close do |e|
  p e
  exit 1
end

ws.on :error do |e|
  p e
end

loop do
  ws.send "foo"
end

This is probably because I cannot specify an event name for the message as is expected for websocket-rails communication. Is there somehow a way to communicate with a rails (or python) client with the websocket-rails websocket?

0

There are 0 best solutions below