Class: Coronet::Protocol
- Inherits:
-
Object
- Object
- Coronet::Protocol
- Defined in:
- lib/coronet/protocol.rb
Instance Attribute Summary collapse
-
#message_format ⇒ Object
Returns the value of attribute message_format.
-
#transport_mechanism ⇒ Object
Returns the value of attribute transport_mechanism.
Instance Method Summary collapse
-
#initialize(message_format, transport_mechanism) ⇒ Protocol
constructor
A new instance of Protocol.
- #read(io) ⇒ Object
- #transmit(request, host, port) ⇒ Object
- #write(data, io) ⇒ Object
Constructor Details
#initialize(message_format, transport_mechanism) ⇒ Protocol
Returns a new instance of Protocol.
6 7 8 9 |
# File 'lib/coronet/protocol.rb', line 6 def initialize(, transport_mechanism) @message_format = @transport_mechanism = transport_mechanism end |
Instance Attribute Details
#message_format ⇒ Object
Returns the value of attribute message_format.
3 4 5 |
# File 'lib/coronet/protocol.rb', line 3 def @message_format end |
#transport_mechanism ⇒ Object
Returns the value of attribute transport_mechanism.
4 5 6 |
# File 'lib/coronet/protocol.rb', line 4 def transport_mechanism @transport_mechanism end |
Instance Method Details
#read(io) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/coronet/protocol.rb', line 11 def read(io) # packed = # unpacked = @message_format.unpack(@transport_mechanism.read(io)) # unpacked end |
#transmit(request, host, port) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/coronet/protocol.rb', line 22 def transmit(request, host, port) # puts "=== opening connection to #{host}:#{port}" io = @transport_mechanism.open(host,port) # puts "--- writing #{request} to #{host}:#{port}" write(request, io) # puts "=== reading response from #{host}:#{port}" response = read(io) # puts "--- closing socket to #{host}:#{port}" @transport_mechanism.close(io) # puts "=== returning response #{response} from #{host}:#{port}" response end |
#write(data, io) ⇒ Object
18 19 20 |
# File 'lib/coronet/protocol.rb', line 18 def write(data, io) @transport_mechanism.write(@message_format.pack(data), io) end |