Sha256: dcb2ab32a6236645bb4389479708dd9e2fe20d106bf8e33d98e974b52cc69d54

Contents?: true

Size: 704 Bytes

Versions: 129

Compression:

Stored size: 704 Bytes

Contents

#!/usr/bin/env ruby

require 'rubygems' # or use Bundler.setup
require 'eventmachine'

class SimpleChatServer < EM::Connection

  @@connected_clients = Array.new


  #
  # EventMachine handlers
  #

  def post_init
    @@connected_clients.push(self)
    puts "A client has connected..."
  end

  def unbind
    @@connected_clients.delete(self)
    puts "A client has left..."
  end




  #
  # Helpers
  #

  def other_peers
    @@connected_clients.reject { |c| self == c }
  end # other_peers
end

EventMachine.run do
  # hit Control + C to stop
  Signal.trap("INT")  { EventMachine.stop }
  Signal.trap("TERM") { EventMachine.stop }

  EventMachine.start_server("0.0.0.0", 10000, SimpleChatServer)
end

Version data entries

129 entries across 126 versions & 10 rubygems

Version Path
sensu-em-2.1.0-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
sensu-em-2.1.0 examples/guides/getting_started/05_simple_chat_server_step_two.rb
sensu-em-2.0.0-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
sensu-em-2.0.0 examples/guides/getting_started/05_simple_chat_server_step_two.rb
sonixlabs-eventmachine-java-1.0.0.rc.7-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.3-x86-mswin32-60 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.3-x86-mingw32 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.3-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.3 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.2-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.2-x86-mswin32-60 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.2-x86-mingw32 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.2 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.1-x86-mswin32-60 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.1-x86-mingw32 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.1-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-1.0.1 examples/guides/getting_started/05_simple_chat_server_step_two.rb
eventmachine-maglev--1.0.0 examples/guides/getting_started/05_simple_chat_server_step_two.rb
sonixlabs-eventmachine-java-1.0.0.rc.5-java examples/guides/getting_started/05_simple_chat_server_step_two.rb
sonixlabs-eventmachine-java-1.0.0.rc.4-java examples/guides/getting_started/05_simple_chat_server_step_two.rb