class MudServer
The server class creates a single instance of a mud server.
Attributes
connection_acceptor[RW]
connection_pool[RW]
environment[RW]
ip[RW]
port[RW]
tcp_socket[RW]
Public Class Methods
new(ip = "0.0.0.0", port = 4000, environment = 'development')
click to toggle source
# File lib/mud_server.rb, line 7 def initialize(ip = "0.0.0.0", port = 4000, environment = 'development') bootstrap_settings(ip, port, environment) end
Public Instance Methods
bootstrap_settings(ip, port, environment)
click to toggle source
# File lib/mud_server.rb, line 11 def bootstrap_settings(ip, port, environment) @port = port @ip = ip @environment = environment @connection_pool = [] # This is where we keep reference to all game # connections end
start()
click to toggle source
# File lib/mud_server.rb, line 19 def start @tcp_socket = TCPServer.new @ip , @port @connection_acceptor = Thread.new do while connection = @tcp_socket.accept @connection_pool << MudServer::Session.new(connection) end end return true end
stop()
click to toggle source
You probably won’t need this one in production, but it’s a must for testing.
# File lib/mud_server.rb, line 30 def stop @tcp_socket.close @connection_acceptor.kill @connection_acceptor = nil return true end