Class: Takagi::Network::Udp

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

Overview

UDP transport implementation (RFC 7252)

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/udp.rb', line 14

def self.additional_schemes
  ['coaps'] # DTLS variant
end

.default_portObject



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

def self.default_port
  5683
end

.reliable?Boolean

Returns:

  • (Boolean)


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

def self.reliable?
  false
end

.rfcObject



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

def self.rfc
  'RFC 7252'
end

.schemeObject



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

def self.scheme
  'coap'
end

Instance Method Details

#create_client(options = {}) ⇒ Object

Create UDP client (internal UdpClient class from client.rb)



53
54
55
56
57
58
# File 'lib/takagi/network/udp.rb', line 53

def create_client(options = {})
  # UdpClient is defined inside client.rb
  # We'll return the class reference for now
  # The actual instantiation happens in Client
  :udp_client
end

#create_sender(options = {}) ⇒ Object

Create UDP sender



41
42
43
44
# File 'lib/takagi/network/udp.rb', line 41

def create_sender(options = {})
  require_relative 'udp_sender'
  UdpSender.instance
end

#create_server(options = {}) ⇒ Object

Create UDP server



47
48
49
50
# File 'lib/takagi/network/udp.rb', line 47

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

#decode(data) ⇒ Object

Decode UDP datagram into message



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

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

#encode(message) ⇒ Object

Encode message for UDP transport (RFC 7252 format)



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

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