Sha256: 6bf752a8327fb6224f6085ed5342ae364e79fb7290a358174c70443625e1830a

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module EventMachine
  module WebSocket
    class WebSocketError < RuntimeError; end
    class HandshakeError < WebSocketError; end
    class DataError < WebSocketError; end

    #backwards compatibility
    def self.start(options, &blk)
      self.start_ws_server(options, &blk)
    end

    def self.start_ws_server(options, &blk)
      EM.epoll
      EM.run do

        #trap("TERM") { stop; }
        #trap("INT") { stop; }

        EventMachine::start_server(options[:host], options[:port],
          EventMachine::WebSocket::Connection, options) do |c|
          blk.call(c)
        end
      end
    end

    def self.start_ws_client(options, &blk)
      EM.epoll
      EM.run do

        #trap("TERM") { stop; raise "TERM" }
        #trap("INT")  { stop; raise "INT" }

        EM.connect(options[:host], options[:port],
          EventMachine::WebSocket::ClientConnection, options) do |c|
          blk.call(c)
        end
      end
    end

    def self.stop
      puts "Terminating WebSocket Server"
      EventMachine.stop
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sonixlabs-em-websocket-0.3.8 lib/em-websocket/websocket.rb
sonixlabs-em-websocket-0.3.7 lib/em-websocket/websocket.rb