Class: LocalMessageRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/local_message/local_message_router.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listening_port) ⇒ LocalMessageRouter

Returns a new instance of LocalMessageRouter.



7
8
9
10
# File 'lib/local_message/local_message_router.rb', line 7

def initialize(listening_port)
  @port = listening_port
  @registered_users = {}
end

Instance Attribute Details

#open_portsObject (readonly)

Returns the value of attribute open_ports.



5
6
7
# File 'lib/local_message/local_message_router.rb', line 5

def open_ports
  @open_ports
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/local_message/local_message_router.rb', line 5

def port
  @port
end

#registered_usersObject (readonly)

Returns the value of attribute registered_users.



5
6
7
# File 'lib/local_message/local_message_router.rb', line 5

def registered_users
  @registered_users
end

Instance Method Details

#startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/local_message/local_message_router.rb', line 12

def start
  server = TCPServer.open(port)
  begin

    Thread.start(server.accept) do |client|
      fam, port, hostname, ip = client.peeraddr
      message = client.read
      handle(message, port, ip)
      client.close
    end

  end while true
end