Class: KRPC::RPCConnection

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

Overview

TCP connection for sending RPC calls and retrieving its 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?, #protobuf_handshake, #receive_message, #recv, #recv_varint, #send, #send_message

Constructor Details

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

Returns a new instance of RPCConnection.



92
93
94
95
# File 'lib/krpc/connection.rb', line 92

def initialize(name = Client::DEFAULT_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.



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

def client_id
  @client_id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#cleanupObject



103
104
105
# File 'lib/krpc/connection.rb', line 103

def cleanup
  @client_id = nil
end

#handshakeObject

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



98
99
100
101
# File 'lib/krpc/connection.rb', line 98

def handshake
  resp = protobuf_handshake(:RPC, client_name: name)
  @client_id = resp.client_identifier
end