Class: TacviewClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tacview_client/client.rb

Overview

The actual client to be instantiated to connect to a Tacview Server

Constant Summary collapse

STREAM_PROTOCOL =

The underlying stream protocol used by Tacview. Needs to be in-sync between the client and the server.

'XtraLib.Stream.0'
TACVIEW_PROTOCOL =

The application level protocol used by Tacview. Needs to be in-sync between the client and the server.

'Tacview.RealTimeTelemetry.0'
HANDSHAKE_TERMINATOR =

A null terminator used by Tacview to terminate handshake packages

"\0"
PASSWORD_HASHER =

Passwords sent between Tacview clients and servers are hashed using this algorithm

CRC['CRC-64-ECMA']

Instance Method Summary collapse

Constructor Details

#initialize(host:, port: 42_674, password: nil, processor:, client_name: 'ruby_tacview_client') ⇒ Client

Returns a new instance of a Client

This is the entry point into the gem. Instantiate an instance of this class to setup the prerequisite data for a connection to a Tacview server. Once done call #connect to start processing the Tacview ACMI stream.

Parameters:

  • host (String)

    Server hostname or IP

  • port (Integer) (defaults to: 42_674)

    Server port

  • password (String) (defaults to: nil)

    Plaintext password required to connect to a password protected Tacview server. Is hashed before transmission.

  • client_name (String) (defaults to: 'ruby_tacview_client')

    Client name to send to the server

  • processor (BaseProcessor)

    The object that processes the events emitted by the Reader. Must implement the methods defined by the BaseProcessor and can optionally inherit from it.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tacview_client/client.rb', line 40

def initialize(host:,
               port: 42_674,
               password: nil,
               processor:,
               client_name: 'ruby_tacview_client')
  @host = host
  @port = port
  @password = password
  @processor = processor
  @client_name = client_name
end

Instance Method Details

#connectObject

Connect to the Tacview server

Actually opens a TCP connection to the Tacview server and starts streaming ACMI lines to an instance of the Reader class.

This method will only return when the TCP connection has be killed either by a client-side signal or by the server closing the TCP connection.



60
61
62
63
64
65
66
67
68
# File 'lib/tacview_client/client.rb', line 60

def connect
  @connection = TCPSocket.open(@host, @port)

  read_handshake

  send_handshake

  start_reader
end