examples/chat/server.rb in async-io-1.12.2 vs examples/chat/server.rb in async-io-1.12.3
- old
+ new
@@ -20,12 +20,11 @@
@name || "unknown"
end
end
class Server
- def initialize(endpoint)
- @endpoint = endpoint
+ def initialize
@users = Set.new
end
def broadcast(*message)
puts *message
@@ -59,13 +58,13 @@
@users.delete(user)
broadcast("#{user} has disconnected: #{reason}")
end
- def run
+ def run(endpoint)
Async::Reactor.run do |task|
- @endpoint.accept do |peer|
+ endpoint.accept do |peer|
stream = Async::IO::Stream.new(peer)
user = User.new(stream)
@users << user
@@ -73,9 +72,11 @@
end
end
end
end
-endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7138")
-server = Server.new(endpoint)
+Async.logger.level = Logger::INFO
+Async.logger.info("Starting server...")
+server = Server.new
-server.run
+endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7138")
+server.run(endpoint)