Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't connect websocket when start rails with -d. #153

Open
famince opened this issue May 18, 2019 · 0 comments
Open

can't connect websocket when start rails with -d. #153

famince opened this issue May 18, 2019 · 0 comments

Comments

@famince
Copy link

famince commented May 18, 2019

it's ok when start rails with command: rails s -b0.0.0.0 -p8080.

but start rails with command:rails s -b0.0.0.0 -p8080 -d
can't connect to websocket

server:
config/initializers/websocket.rb
EM.run {
EM::WebSocket.run(:host => "0.0.0.0", :port => 8082) do |ws|
ws.onopen { |handshake|
puts "WebSocket connection open"

  # Access properties on the EM::WebSocket::Handshake object, e.g.
  # path, query_string, origin, headers

  # Publish message to the client
  ws.send "Hello Client, you connected to #{handshake.path}"
}

ws.onclose { puts "Connection closed" }

ws.onmessage { |msg|
  puts "Recieved message: #{msg}"
  ws.send "Pong: #{msg}"
}

end
}

client:
html file

<script> var ws = new WebSocket("ws://*.*.*.*:8082"); ws.onopen = function() { alert("websocket is connected..."); ws.send('send from browser'); }; ws.onmessage = function (evt) { var msg = evt.data; alert("Message is received..." + msg); }; ws.onclose = function() { alert("Connection is closed..."); }; </script> websocket test
@famince famince changed the title can't listen port when start rails with -d. can't connect websocket when start rails with -d. May 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant