Skip to content

Instantly share code, notes, and snippets.

@kyledrake
Created February 26, 2013 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyledrake/5041357 to your computer and use it in GitHub Desktop.
Save kyledrake/5041357 to your computer and use it in GitHub Desktop.
debugging
#!/usr/bin/env ruby
require 'celluloid/io'
require 'json'
require 'websocket'
class WebsocketClient
include Celluloid::IO
def initialize(host, port)
puts "*** Connecting to echo server on #{host}:#{port}"
@socket = TCPSocket.new(host, port)
@handshake = WebSocket::Handshake::Client.new(:url => "ws://#{host}:#{port}")
@socket.write @handshake.to_s
payload = ->(num){ ['test', {name: 'Captain Test', number: num}].to_json }
100_000.times {|i|
frame = WebSocket::Frame::Outgoing::Server.new(:version => @handshake.version, :data => payload.call(i), :type => :text)
@socket.write frame.to_s
}
end
end
client = WebsocketClient.new("127.0.0.1", 1234)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment