'No Response After Sending Websocket Request Ruby on Rails

I want to observe the websocket protocol and networking and I was using the code below to watch the response.

require 'socket'

body = <<~EOF
    GET ws://localhost:3000/cable HTTP/1.1\r
    Host: localhost:3000\r
    Connection: Upgrade\r
    Upgrade: websocket\r
    Origin: http://localhost:3000\r
    \r
  EOF

Socket.tcp("localhost", 3000){|sock|
    sock.print body
    sock.close_write
    puts sock.read
}

However, after I send out the request, the terminal is not printing anything to me. May I know why?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source