Class: KRPC::StreamConnection

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

Overview

TCP connection for streaming.

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

#cleanup, #close, #connect, #connected?, #protobuf_handshake, #receive_message, #recv, #recv_varint, #send, #send_message

Constructor Details

#initialize(rpc_connection, host = DEFAULT_SERVER_HOST, port = DEFAULT_SERVER_STREAM_PORT) ⇒ StreamConnection

Returns a new instance of StreamConnection.



113
114
115
116
# File 'lib/krpc/connection.rb', line 113

def initialize(rpc_connection, host = DEFAULT_SERVER_HOST, port = DEFAULT_SERVER_STREAM_PORT)
  super host, port
  @rpc_connection = rpc_connection
end

Instance Attribute Details

#rpc_connectionObject (readonly)

Returns the value of attribute rpc_connection.



111
112
113
# File 'lib/krpc/connection.rb', line 111

def rpc_connection
  @rpc_connection
end

Instance Method Details

#handshakeObject

Perform handshake with kRPC server, sending ‘client_id` retrieved from `rpc_connection`.

Raises:



119
120
121
122
# File 'lib/krpc/connection.rb', line 119

def handshake
  raise(ConnectionError, "RPC connection must obtain client_id before stream connection can perform valid handshake - closing stream connection") if rpc_connection.client_id.nil?
  protobuf_handshake(:STREAM, client_identifier: rpc_connection.client_id)
end