Sha256: a46688224ecdc23641903404ac3b5ed90c646a5c30a320aefcfcb9efc82725c2

Contents?: true

Size: 619 Bytes

Versions: 1

Compression:

Stored size: 619 Bytes

Contents

require 'rubygems'
require 'bundler/setup'
require 'faye/websocket'
require 'eventmachine'

port   = ARGV[0] || 7000
secure = ARGV[1] == 'ssl'

EM.run {
  scheme = secure ? 'wss' : 'ws'
  url    = "#{scheme}://localhost:#{port}/"
  socket = Faye::WebSocket::Client.new(url)

  puts "Connecting to #{socket.url}"

  socket.onopen = lambda do |event|
    p [:open]
    socket.send("Hello, WebSocket!")
  end

  socket.onmessage = lambda do |event|
    p [:message, event.data]
    # socket.close 1002, 'Going away'
  end

  socket.onclose = lambda do |event|
    p [:close, event.code, event.reason]
    EM.stop
  end
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faye-websocket-0.5.0 examples/client.rb