0

I'm a little new to Ruby - please be gentle!

I have installed Ruby 1.9.3 on my Windows PC along with the DevKit. I carefully followed the instructions for setting up the devkit.

I then installed the ruby gem for simple-websocket-client:

C:\DevKit>gem install websocket-client-simple
Fetching: websocket-1.2.2.gem (100%)
Fetching: event_emitter-0.2.5.gem (100%)
Fetching: websocket-client-simple-0.2.4.gem (100%)
Successfully installed websocket-1.2.2
Successfully installed event_emitter-0.2.5
Successfully installed websocket-client-simple-0.2.4
3 gems installed
Installing ri documentation for websocket-1.2.2...
Installing ri documentation for event_emitter-0.2.5...
Installing ri documentation for websocket-client-simple-0.2.4...
Installing RDoc documentation for websocket-1.2.2...
Installing RDoc documentation for event_emitter-0.2.5...
Installing RDoc documentation for websocket-client-simple-0.2.4...

C:\DevKit>```

So far so good.

Now I try to use the simple demo script shown on the github page for the gem:

require 'rubygems'
require 'websocket-client-simple'
ws = Websocket::Client::Simple.connect 'wss://WN72REA4.companyname.com:8181/channel'

And I get:-

C:/Users/me/Documents/YY5/rubyscripts/websocket-demo.rb:4:in `<main>': uninitialized constant Websocket (NameError)

Can someone tell me where I am going wrong please? Googling around I see a few hits for this kind of issue, but they mostly read as though they were fixed by trial and error. Would appreciate any advice on where I am going wrong.

Thanks!

1 Answer 1

1

My first point isn't an answer per se, but I would like to point out that Ruby 1.9.3 is OLD. current Ruby is 2.2.3 and there's a preview 2.3.0 release... I recommend that you update to Ruby 2.2.3.

As for the answer:

You issue is related to the fact that Ruby, like most programming languages, is Case Sensitive.

You code uses Websocket instead of WebSocket (notice the capital S)... it should probably read:

ws = WebSocket::Client::Simple.connect 'wss://WN72REA4.companyname.com:8181/channel'
Sign up to request clarification or add additional context in comments.

5 Comments

Hi Myst Thanks for this. I had started out with Ruby 2.2.3 but when I run into issues with gems (like this) I was advised to try 1.9.3 for compatibility. Changing the case - as you pointed out - helps. Thank you. I should have noticed that! My next issue is that I'm using: ws.on :open do ws.send '{"connection-information":{}}' end To send json to the server and using:- ws.on :message do |msg| puts msg.data end to process anything coming back. At the moment there is nothing being output. Again any advice appreciated. Thanks again.
Hi. You're very welcome. I would love to see if I can help with your second question, but it's very hard to read and debug your code in a comment. Maybe you could post it as a second question and post a link back here in a comment?
@user3202399 P.S., please accept any answers that answer the question. It marks the question as answered, helping future readers and it's a great way to give positive feedback.
Are you sure the server is sending you any data?
Great advice. Your answer is accepted and I will post a new question about why I get nothing back from the websocket server (works perfectly in Chrome and using Java/Jetty). Really appreciate your interest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.