JavaScript WebSocket handshake with Ruby and EM::WebSocket::Server websocket with handshake,websocket handshake in c,websocket handshake for

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following:

WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing

What am I doing wrong? Here is my code:

JavaScript:

var socket = new WebSocket('ws://localhost:4000');

socket.onopen = function() {
  var handshake =
    "GET / HTTP/1.1\n" +
    "Host: localhost\n" +
    "Upgrade: websocket\n" +
    "Connection: Upgrade\n" +
    "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\n" +
    "Sec-WebSocket-Protocol: quote\n" +
    "Sec-WebSocket-Version: 13\n" +
    "Origin: http://localhost\n";

  socket.send(handshake);
};

socket.onmessage = function(data) {
  console.log(data);
};

Ruby:

require 'rubygems'
require 'em-websocket-server'

module QuoteService
  class WebSocket < EventMachine::WebSocket::Server
    def on_connect
      handshake_response =  "HTTP/1.1 101 Switching Protocols\n"
      handshake_response << "Upgrade: websocket\n"
      handshake_response << "Connection: Upgrade\n"
      handshake_response << "Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=\n"
      handshake_response << "Sec-WebSocket-Protocol: quote\n"

      send_message(handshake_response)
    end

    def on_receive(data)
      puts 'RECEIVED: ' + data
    end
  end
end

EventMachine.run do
  print 'Starting WebSocket server...'
  EventMachine.start_server '0.0.0.0', 4000, QuoteService::WebSocket
  puts 'running'
end

The handshake headers are per Wikipedia.

Answer:1

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

I've got some code that sends an ajax request when a form is being submitted. This works the first time the form is submitted (it's a search module), but only once. I've added an effect to highlight ...

I've got some code that sends an ajax request when a form is being submitted. This works the first time the form is submitted (it's a search module), but only once. I've added an effect to highlight ...

  1. response from ajax call
  2. response from ajax
  3. response from ajax post
  4. return response from ajax call
  5. get response from ajax
  6. get response from ajax call jquery
  7. get response from ajax post
  8. get response from ajax call
  9. get response from ajax jquery
  10. download response from ajax
  11. get response from ajax request
  12. get response from ajax javascript
  13. return response from ajax
  14. ajax call without response
  15. get response from ajax call javascript
  16. no response from ajax jquery
  17. alert response from ajax
  18. response.redirect from ajax call
  19. json response from ajax call
  20. return response from ajax success

I'm replacing the smiley shortcuts from my text editor with img tags, but the logic I use also sees parts of links and tags as smiley shortcuts (e.g. :/ in http://, or :p in cursor:pointer in the ...

I'm replacing the smiley shortcuts from my text editor with img tags, but the logic I use also sees parts of links and tags as smiley shortcuts (e.g. :/ in http://, or :p in cursor:pointer in the ...

Here is my angular js app with html code <html> <head> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <...

Here is my angular js app with html code <html> <head> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <...