I have this simple javascript code:
window.ws = new WebSocket('ws://127.0.0.1:8000/'); ws.onopen = function() { ws.send('hello'); }
And the server in Ruby is like this:
require 'em-websocket' class Websocket def run EventMachine.run do EM::WebSocket.start(host: '0.0.0.0', port: '8000') do |ws| ws.onopen do |handshake| puts "Connected" end ws.onclose do puts "Closed" end ws.onmessage do |msg| p msg end end end end end
When the connection is closed, the server should print “Closed”. In the browser, when I do window.ws.close() , the server does not receive anything, but when I reload the page, it prints a message.
Is there a way to make the client say the connection is closed?
source share