class Fix::Engine::Client

Represents a connected client

Attributes

connection[RW]
ip[RW]
port[RW]
username[RW]

Public Class Methods

count() click to toggle source

Returns the count of currently connected clients

@return [Fixnum] The client count

# File lib/fix/engine/client.rb, line 42
def self.count
  @clients.count
end
delete(ip, port) click to toggle source

Removes a client from the currently connected ones

@param ip [String] The client’s remote IP @param port [Fixnum] The client’s port

# File lib/fix/engine/client.rb, line 52
def self.delete(ip, port)
  @clients.delete(key(ip, port))
end
get(ip, port, connection = nil) click to toggle source

Returns a client instance from its connection IP

@param ip [String] The connection IP @param port [Fixnum] The connection port @param connection [FE::Connection] Optionnally the connection which will used to create an instance if none exists @return [Fix::Engine::Client] The client connected for this IP

# File lib/fix/engine/client.rb, line 33
def self.get(ip, port, connection = nil)
  @clients[key(ip, port)] || Client.new(ip, port, connection)
end
key(ip, port) click to toggle source

Returns an identifier for the given IP and port

@param ip [String] The client’s remote IP @param port [Fixnum] The client’s port

@return [String] An identifier

# File lib/fix/engine/client.rb, line 80
def self.key(ip, port)
  "#{ip}:#{port}"
end
new(ip, port, connection) click to toggle source
# File lib/fix/engine/client.rb, line 17
def initialize(ip, port, connection)
  @ip         = ip
  @port       = port
  @connection = connection
 
  self.class.instance_variable_get(:@clients)[key] = self 
end

Public Instance Methods

delete() click to toggle source

Removes the current client from the array of connected ones

# File lib/fix/engine/client.rb, line 68
def delete
  self.class.delete(ip, port)
end
key() click to toggle source

Returns an identifier for the current client

@return [String] An identifier

# File lib/fix/engine/client.rb, line 61
def key
  self.class.key(ip, port)
end