Class: Porous::Server::Socket
- Inherits:
-
Object
- Object
- Porous::Server::Socket
- Defined in:
- lib/porous/server/socket.rb
Instance Method Summary collapse
-
#initialize ⇒ Socket
constructor
A new instance of Socket.
- #on_close(client) ⇒ Object
- #on_drained(_client) ⇒ Object
- #on_message(client, data) ⇒ Object
- #on_open(client) ⇒ Object
- #public(channel, message) ⇒ Object
Constructor Details
#initialize ⇒ Socket
Returns a new instance of Socket.
6 7 8 9 |
# File 'lib/porous/server/socket.rb', line 6 def initialize @clients = [] @mutex = Mutex.new end |
Instance Method Details
#on_close(client) ⇒ Object
17 18 19 20 21 |
# File 'lib/porous/server/socket.rb', line 17 def on_close(client) @mutex.synchronize do @clients.delete(client) end end |
#on_drained(_client) ⇒ Object
23 |
# File 'lib/porous/server/socket.rb', line 23 def on_drained(_client); end |
#on_message(client, data) ⇒ Object
25 26 27 |
# File 'lib/porous/server/socket.rb', line 25 def (client, data) client.write("Handler says #{data}") end |
#on_open(client) ⇒ Object
11 12 13 14 15 |
# File 'lib/porous/server/socket.rb', line 11 def on_open(client) @mutex.synchronize do @clients << client end end |
#public(channel, message) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/porous/server/socket.rb', line 29 def public(channel, ) output = "#{channel}|#{}" @mutex.synchronize do @clients.each do |c| c.write output end end end |