Class: IRC::Commands::PingCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/irc/commands/ping_command.rb

Overview

4.6.2 Ping message

Command: PING Parameters: <server1> [<server2>]

The PING message is used to test the presence of an active client at the other end of the connection. A PING message is sent at regular intervals if no other activity detected coming from a connection. If a connection fails to respond to a PING command within a set amount of time, that connection is closed.

Any client which receives a PING message must respond to <server1> (server which sent the PING message out) as quickly as possible with an appropriate PONG message to indicate it is still there and alive. Servers should not respond to PING commands but rely on PINGs from the other end of the connection to indicate the connection is alive. If the <server2> parameter is specified, the PING message gets forwarded there.

Numeric Replies:

  • ERR_NOORIGIN

  • ERR_NOSUCHSERVER

Examples:

PING tolsun.oulu.fi ; server sending a PING message to

another server to indicate it is still
alive.

PING WiZ ; PING message being sent to nick WiZ

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#send, #to_s

Constructor Details

#initialize(first_server, second_server = nil) ⇒ PingCommand

Returns a new instance of PingCommand.

Raises:



66
67
68
69
# File 'lib/irc/commands/ping_command.rb', line 66

def initialize(first_server, second_server = nil)
  raise InvalidCommand.new("Can't create ping command. No server.") unless first_server
  @first_server, @second_server = first_server, second_server
end

Instance Attribute Details

#first_serverObject (readonly)

Returns the value of attribute first_server.



63
64
65
# File 'lib/irc/commands/ping_command.rb', line 63

def first_server
  @first_server
end

#second_serverObject (readonly)

Returns the value of attribute second_server.



64
65
66
# File 'lib/irc/commands/ping_command.rb', line 64

def second_server
  @second_server
end

Instance Method Details

#commandObject



71
72
73
# File 'lib/irc/commands/ping_command.rb', line 71

def command
  return "PING #{first_server} #{second_server != nil ? second_server.to_s : ''}".strip
end