stevefolder/vendor/bundle/ruby/3.1.0/gems/websocket-client-simple-0.5.1/sample/client.rb
2022-02-04 18:48:09 -05:00

32 lines
579 B
Ruby

#!/usr/bin/env ruby
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'rubygems'
require 'websocket-client-simple'
puts "websocket-client-simple v#{WebSocket::Client::Simple::VERSION}"
url = ARGV.shift || 'ws://localhost:8080'
ws = WebSocket::Client::Simple.connect url
ws.on :message do |msg|
puts ">> #{msg.data}"
end
ws.on :open do
puts "-- websocket open (#{ws.url})"
end
ws.on :close do |e|
puts "-- websocket close (#{e.inspect})"
exit 1
end
ws.on :error do |e|
puts "-- error (#{e.inspect})"
end
loop do
ws.send STDIN.gets.strip
end