Skip to content

Instantly share code, notes, and snippets.

# coding: utf-8
require "socket"
require 'libwebsocket'
require 'eventmachine'
class WebSocket
def initialize(url, params = {})
@hs ||= LibWebSocket::OpeningHandshake::Client.new(:url => url, :version => params[:version])
@Burgestrand
Burgestrand / em-fiber.rb
Created March 6, 2011 18:54
An experiment using Fibers together with EventMachine
# coding: utf-8
require 'eventmachine'
module EM
module Strand
extend self
# Fires up EventMachine in a fiber, ready to take orders.
#
# @return EM::Strand
@pfleidi
pfleidi / fiberchat.rb
Created February 19, 2011 18:51
A naive socket chat using select() and ruby fibers
require 'rubygems'
require 'socket'
include Socket::Constants
class ChatServer
def initialize
@reading = Array.new
@writing = Array.new
@clients = Hash.new
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Footnotes::Application.initialize!
# Start the websocket server
Footnotes::WebSocketServer.new(10081)