Class: Takagi::Network::Tcp

Inherits:
Base show all
Defined in:
lib/takagi/network/tcp.rb

Overview

TCP transport implementation (RFC 8323)

Constant Summary

Constants inherited from Router

Router::DEFAULT_CONTENT_FORMAT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

core, observable, router

Methods included from Base::ServerLifecycle

#boot!, #run!, #spawn!

Methods included from Base::MiddlewareManagement

#call, #middleware_stack, #use

Methods included from Base::ReactorManagement

#reactor, #start_reactors, #stop_reactors, #use_reactor

Methods included from Base::PluginManagement

#enable_plugins!, #plugin

Methods inherited from Router

#add_route, #all_routes, #configure_core, #find_observable, #find_route, #initialize, instance, #link_format_entries, #observable, reset!

Constructor Details

This class inherits a constructor from Takagi::Router

Class Method Details

.additional_schemesObject



14
15
16
# File 'lib/takagi/network/tcp.rb', line 14

def self.additional_schemes
  ['coaps+tcp'] # TLS variant
end

.default_portObject



18
19
20
# File 'lib/takagi/network/tcp.rb', line 18

def self.default_port
  5683
end

.reliable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/takagi/network/tcp.rb', line 26

def self.reliable?
  true
end

.rfcObject



22
23
24
# File 'lib/takagi/network/tcp.rb', line 22

def self.rfc
  'RFC 8323'
end

.schemeObject



10
11
12
# File 'lib/takagi/network/tcp.rb', line 10

def self.scheme
  'coap+tcp'
end

Instance Method Details

#create_client(options = {}) ⇒ Object

Create TCP client



54
55
56
57
# File 'lib/takagi/network/tcp.rb', line 54

def create_client(options = {})
  # TcpClient is a separate class
  :tcp_client
end

#create_sender(options = {}) ⇒ Object

Create TCP sender (currently uses existing TcpSender singleton) TODO: Replace with connection pool in Phase 5



42
43
44
45
# File 'lib/takagi/network/tcp.rb', line 42

def create_sender(options = {})
  require_relative 'tcp_sender'
  TcpSender.instance
end

#create_server(options = {}) ⇒ Object

Create TCP server



48
49
50
51
# File 'lib/takagi/network/tcp.rb', line 48

def create_server(options = {})
  require_relative '../server/tcp'
  Server::Tcp.new(**options)
end

#decode(data) ⇒ Object

Decode TCP stream data into message



36
37
38
# File 'lib/takagi/network/tcp.rb', line 36

def decode(data)
  Framing::Tcp.decode(data)
end

#encode(message) ⇒ Object

Encode message for TCP transport (RFC 8323 format)



31
32
33
# File 'lib/takagi/network/tcp.rb', line 31

def encode(message)
  Framing::Tcp.encode(message)
end