Class: KRPC::RPCConnection

Inherits:
Connection show all
Defined in:
lib/krpc/connection.rb

Overview

TCP connection for sending RPC calls and retrieving it’s results.

Constant Summary

Constants inherited from Connection

Connection::DEFAULT_SERVER_HOST, Connection::DEFAULT_SERVER_RPC_PORT, Connection::DEFAULT_SERVER_STREAM_PORT

Instance Attribute Summary collapse

Attributes inherited from Connection

#host, #port, #socket

Instance Method Summary collapse

Methods inherited from Connection

#close, #connect, #connected?, #recv, #recv_varint, #send

Constructor Details

#initialize(name, host = DEFAULT_SERVER_HOST, port = DEFAULT_SERVER_RPC_PORT) ⇒ RPCConnection

Returns a new instance of RPCConnection.



82
83
84
85
# File 'lib/krpc/connection.rb', line 82

def initialize(name, host = DEFAULT_SERVER_HOST, port = DEFAULT_SERVER_RPC_PORT)
  super host, port
  @name = name
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



80
81
82
# File 'lib/krpc/connection.rb', line 80

def client_id
  @client_id
end

#nameObject (readonly)

Returns the value of attribute name.



80
81
82
# File 'lib/krpc/connection.rb', line 80

def name
  @name
end

Instance Method Details

#cleanupObject

Clean up - sets ‘@client_id` to `nil`.



95
96
97
# File 'lib/krpc/connection.rb', line 95

def cleanup
  @client_id = nil
end

#handshakeObject

Perform handshake with kRPC server, obtaining ‘@client_id`.



88
89
90
91
92
# File 'lib/krpc/connection.rb', line 88

def handshake
  send Encoder::RPC_HELLO_MESSAGE
  send trim_fill(name, Encoder::NAME_LENGTH)
  @client_id = recv Decoder::GUID_LENGTH
end