em-websocket

Sending large file in websocket before timeout

我怕爱的太早我们不能终老 提交于 2019-12-12 02:27:14
问题 I'm using Faye and EventMachine to open a socket to another server. The server times out if it doesn't detect activity. How do I send the file (binary encoded) so the server doesn't time out? Here's what I have: media_path = "/path/to/media/file" EM.run { ws = Faye::WebSocket::Client.new(uri) ws.on :open do |event| puts "Opening socket" ws.send(File.read(media_path)) end ws.on :message do |event| puts "Recieving message" end ws.on :close do |event| ws = nil EM.stop end } 回答1: You need to send

Accessing a variable within a rails thread

混江龙づ霸主 提交于 2019-12-10 16:46:46
问题 I'm building an application for a web-based slide show, where one 'master' user can move between slides and everyone's browsers follow along. To do this, I'm using websockets and Redis for a global channel to send messages through. Each client who connects has there info stored in an array, @clients . Then I have a separate thread for subscribing to the Redis channel, in which there is an 'on.message' block defined which should send a message to everyone in the @clients array, but that array

WebSocket handshake with Ruby and EM::WebSocket::Server

百般思念 提交于 2019-12-01 11:16:04
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" +