Method: Server#initialize

Defined in:
lib/steam/servers/server.rb

#initialize(address, port = nil) ⇒ Object

Creates a new server instance with the given address and port

Parameters:

  • address (String)

    Either an IP address, a DNS name or one of them combined with the port number. If a port number is given, e.g. ‘server.example.com:27016’ it will override the second argument.

  • port (Fixnum) (defaults to: nil)

    The port the server is listening on

Raises:

See Also:

  • #init_socket


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/steam/servers/server.rb', line 34

def initialize(address, port = nil)
  address = address.to_s
  address, port = address.split(':', 2) if address.include? ':'

  @host_names   = []
  @ip_addresses = []
  @ip_index     = 0
  @port         = port

  Socket.getaddrinfo(address, port, Socket::AF_INET, Socket::SOCK_DGRAM).
         each do |address|
    @host_names << address[2]
    @ip_addresses << address[3]
  end

  @ip_address = @ip_addresses.first

  init_socket
end