Class: SteamMist::Rcon::Listener
- Inherits:
-
Object
- Object
- SteamMist::Rcon::Listener
- Extended by:
- Forwardable
- Defined in:
- lib/steam_mist/rcon/listener.rb
Overview
Listens on a TCP stream for packets. This is completely synchronus.
Instance Attribute Summary collapse
-
#connection ⇒ TCPSocket
readonly
The connection the listener is using.
-
#ip ⇒ String
The ip address this listener is bound to.
-
#port ⇒ Numeric
The port the listener is bound to.
Instance Method Summary collapse
-
#bind! ⇒ void
Connect to the set port and ip address.
-
#close ⇒ void
Closes the connection.
-
#closed? ⇒ Boolean
This returns true or false depending on whether or not the connection is closed.
-
#initialize(ip, port) ⇒ Listener
constructor
Initialize the listener.
-
#on_data {|socket| ... } ⇒ void
Listens to the connection for any data; when there is some, it’ll call the block and then return.
-
#write(*args, &block) ⇒ Object
This passes the write through to the connection if the connection isn’t closed.
Constructor Details
#initialize(ip, port) ⇒ Listener
Initialize the listener.
28 29 30 31 32 |
# File 'lib/steam_mist/rcon/listener.rb', line 28 def initialize(ip, port) @ip = ip @port = port @closed = false end |
Instance Attribute Details
#connection ⇒ TCPSocket (readonly)
The connection the listener is using.
22 23 24 |
# File 'lib/steam_mist/rcon/listener.rb', line 22 def connection @connection end |
#ip ⇒ String
The ip address this listener is bound to.
12 13 14 |
# File 'lib/steam_mist/rcon/listener.rb', line 12 def ip @ip end |
#port ⇒ Numeric
The port the listener is bound to.
17 18 19 |
# File 'lib/steam_mist/rcon/listener.rb', line 17 def port @port end |
Instance Method Details
#bind! ⇒ void
This method returns an undefined value.
Connect to the set port and ip address.
37 38 39 |
# File 'lib/steam_mist/rcon/listener.rb', line 37 def bind! @connection = TCPSocket.new ip, port end |
#close ⇒ void
This method returns an undefined value.
Closes the connection.
85 86 87 88 89 90 |
# File 'lib/steam_mist/rcon/listener.rb', line 85 def close unless @closed @closed = true connection.close end end |
#closed? ⇒ Boolean
This returns true or false depending on whether or not the connection is closed.
96 97 98 |
# File 'lib/steam_mist/rcon/listener.rb', line 96 def closed? @closed end |
#on_data {|socket| ... } ⇒ void
This method returns an undefined value.
Listens to the connection for any data; when there is some, it’ll call the block and then return.
72 73 74 75 76 77 78 79 80 |
# File 'lib/steam_mist/rcon/listener.rb', line 72 def on_data return false if closed? result = IO.select [connection], [], [], 10 raise TimeoutError, "timeout" unless result yield connection end |
#write(*args, &block) ⇒ Object
This passes the write through to the connection if the connection isn’t closed.
102 103 104 105 106 |
# File 'lib/steam_mist/rcon/listener.rb', line 102 def write(*args, &block) return false if closed? connection.write(*args, &block) end |