Sha256: 99efba020e819edc44600f89745ab61a278d8ff7ded89d05a626c721c0728394

Contents?: true

Size: 675 Bytes

Versions: 2

Compression:

Stored size: 675 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}/"
  headers = {'Origin' => 'http://faye.jcoglan.com'}
  ws      = Faye::WebSocket::Client.new(url, nil, :headers => headers)

  puts "Connecting to #{ws.url}"

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
faye-websocket-0.7.5 examples/client.rb
faye-websocket-0.7.4 examples/client.rb