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?, #recv, #recv_varint, #send

Constructor Details

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

Returns a new instance of StreamConnection.



105
106
107
108
# File 'lib/krpc/connection.rb', line 105

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.



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

def rpc_connection
  @rpc_connection
end

Instance Method Details

#handshakeObject

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

Raises:



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

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? 
  send Encoder::STREAM_HELLO_MESSAGE
  send rpc_connection.client_id
  resp = recv Decoder::OK_LENGTH
  raise ConnectionError unless resp == Decoder::OK_MESSAGE
end