Sha256: 138dc3ff749072fb29a917af545b3ba40f1deabe30c12e62615206d67e1f34ea
Contents?: true
Size: 894 Bytes
Versions: 3
Compression:
Stored size: 894 Bytes
Contents
#!/usr/bin/env ruby require 'async/reactor' require 'async/io/stream' require 'async/http/url_endpoint' require 'async/websocket/client' USER = ARGV.pop || "anonymous" URL = ARGV.pop || "ws://localhost:9292" Async::Reactor.run do |task| stdin = Async::IO::Stream.new( Async::IO::Generic.new($stdin) ) endpoint = Async::HTTP::URLEndpoint.parse(URL) endpoint.connect do |socket| connection = Async::WebSocket::Client.new(socket, URL) connection.send_message({ user: USER, status: "connected", }) task.async do puts "Waiting for input..." begin while line = stdin.read_until("\n") puts "Sending text: #{line}" connection.send_message({ user: USER, text: line, }) end rescue puts "Client error: #{$!}" end end while message = connection.next_message puts "From server: #{message.inspect}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
async-websocket-0.6.1 | examples/middleware/client.rb |
async-websocket-0.6.0 | examples/middleware/client.rb |
async-websocket-0.5.0 | examples/middleware/client.rb |