Sha256: ec5f46c642212cafdb52166be2b34efb848840e03ddc218cd9f8a21fca95a0b2
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
# # frozen_string_literal: true require 'faye/websocket' require 'eventmachine' require 'json' require 'io/console' module MKIt class ConsoleWebSocketClient def initialize(uri, options) @uri = uri @options = options end def doIt EM.run { ws = Faye::WebSocket::Client.new(@uri, nil, @options) ws.on :open do |_event| puts "Connected to remote server" puts "\r\n" end ws.on :message do |event| print event.data end ws.on :error do |event| p [:error, event.message] ws = nil EventMachine.stop end ws.on :close do |_event| ws = nil puts "\r\n" EventMachine.stop end Thread.new do STDIN.raw do loop do input = STDIN.getc.chr # if input == "\u0003" # Ctrl+C # puts "bye..." # EventMachine.stop # break # else ws.send(input) # end end end end } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mkit-0.9.0 | lib/mkit/client/console_websocket_client.rb |