Class: WildSoNet::Streamer::Server
- Inherits:
-
Object
- Object
- WildSoNet::Streamer::Server
- Defined in:
- lib/server.rb
Class Method Summary collapse
- .push(cid, message) ⇒ Object
- .register(cid, connection) ⇒ Object
- .start(port, address = "0.0.0.0", encoder = WildSoNet::Streamer::Encoder) ⇒ Object
- .unregister(cid, connection) ⇒ Object
Instance Method Summary collapse
-
#initialize(port, address, encoder) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(port, address, encoder) ⇒ Server
Returns a new instance of Server.
21 22 23 24 25 26 |
# File 'lib/server.rb', line 21 def initialize port, address, encoder @factory = NioServerSocketChannelFactory.new(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()) @bootstrap = ServerBootstrap.new(@factory) @bootstrap.setPipelineFactory(PipelineFactory.new(encoder)) @bootstrap.bind(InetSocketAddress.new(address, port)) end |
Class Method Details
.push(cid, message) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/server.rb', line 35 def self.push(cid, ) @@connections[cid.to_s].each do |con| con.write() end if @@connections[cid.to_s] end |
.register(cid, connection) ⇒ Object
43 44 45 46 |
# File 'lib/server.rb', line 43 def self.register(cid, connection) @@connections[cid.to_s] ||= [] @@connections[cid.to_s] << connection end |
.start(port, address = "0.0.0.0", encoder = WildSoNet::Streamer::Encoder) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/server.rb', line 28 def self.start(port, address = "0.0.0.0", encoder=WildSoNet::Streamer::Encoder) @@servers ||= {} @@servers["#{address}:#{port}"] = Server.new(port, address, encoder) @@connections = {} @@receiver = Receiver.new end |
.unregister(cid, connection) ⇒ Object
48 49 50 51 |
# File 'lib/server.rb', line 48 def self.unregister(cid, connection) return if not @@connections[cid.to_s] @@connections[cid.to_s].delete(connection) end |