Class: Srcon::Connection
- Inherits:
-
Object
- Object
- Srcon::Connection
- Defined in:
- lib/srcon/connection.rb
Defined Under Namespace
Classes: AuthenticationFailure
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(host, port, password = nil) ⇒ Connection
constructor
A new instance of Connection.
-
#receive ⇒ Srcon::Packet
The deconstructed packet received from the socket.
-
#send(message, type = Srcon::Packet::SERVERDATA_EXECCOMMAND) ⇒ Integer
The number of bytes that were sent.
Constructor Details
#initialize(host, port, password = nil) ⇒ Connection
Returns a new instance of Connection.
12 13 14 15 16 17 18 |
# File 'lib/srcon/connection.rb', line 12 def initialize(host, port, password = nil) @host = host @port = port @id = rand(Process.pid) connect!(password) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/srcon/connection.rb', line 7 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/srcon/connection.rb', line 7 def port @port end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
7 8 9 |
# File 'lib/srcon/connection.rb', line 7 def socket @socket end |
Instance Method Details
#receive ⇒ Srcon::Packet
Returns The deconstructed packet received from the socket.
21 22 23 |
# File 'lib/srcon/connection.rb', line 21 def receive Srcon::Packet.(*socket.recvmsg) end |
#send(message, type = Srcon::Packet::SERVERDATA_EXECCOMMAND) ⇒ Integer
Returns The number of bytes that were sent.
29 30 31 32 33 |
# File 'lib/srcon/connection.rb', line 29 def send(, type = Srcon::Packet::SERVERDATA_EXECCOMMAND) packet = Srcon::Packet.new(, type, @id) @id += 1 socket&.sendmsg(packet.to_b) end |