Class: SimpleSocket
- Inherits:
-
Object
- Object
- SimpleSocket
- Defined in:
- lib/simple_socket.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
10
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(host, port, timeout = DEFAULT_TIMEOUT) ⇒ SimpleSocket
constructor
A new instance of SimpleSocket.
- #write(message) ⇒ Object
Constructor Details
#initialize(host, port, timeout = DEFAULT_TIMEOUT) ⇒ SimpleSocket
Returns a new instance of SimpleSocket.
8 9 10 11 12 |
# File 'lib/simple_socket.rb', line 8 def initialize(host, port, timeout = DEFAULT_TIMEOUT) @host = host @port = port @timeout = timeout end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/simple_socket.rb', line 5 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/simple_socket.rb', line 5 def port @port end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/simple_socket.rb', line 5 def timeout @timeout end |
Instance Method Details
#write(message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_socket.rb', line 14 def write() begin socket = TCPSocket.new(host, port) socket.puts() response = nil Timeout::timeout(timeout) do response = socket.read end ensure socket.close if socket end response end |