class RaptorIO::Socket::Comm
Provides the basic interface that a derived class must implement in order to be a routable socket creator.
See {RaptorIO::Socket::Comm::Local} for an implementation using sockets created with standard Ruby Socket classes.
Subclasses must implement the following methods:
* `resolve` * `create_tcp` * `create_tcp_server` * `create_udp` * `create_udp_server` * `support_ipv6?`
Public Class Methods
@param uri [URI]
# File lib/raptor-io/socket/comm.rb, line 28 def self.from_uri(uri, opts = {}) raise ArgumentError unless uri.kind_of? URI prev_comm = opts[:prev_comm] || RaptorIO::Socket::Comm::Local.new comm = case uri.scheme.downcase when "sapni" uri.port ||= 3299 RaptorIO::Socket::Comm::SAPNI.new( sap_host: uri.host, sap_port: uri.port, sap_comm: prev_comm, ) when "socks" uri.port ||= 1080 RaptorIO::Socket::Comm::SOCKS.new( socks_host: uri.host, socks_port: uri.port, socks_comm: prev_comm, ) end comm end
Public Instance Methods
Creates a socket on this Comm
based on the supplied uniform parameters.
@option options :switch_board [SwitchBoard] @option options :port [Fixnum] Optional based on proto @option options :protocol [Symbol]
* `:tcp` * `:udp`
@return [RaptorIO::Socket]
# File lib/raptor-io/socket/comm.rb, line 63 def create( options ) options = options.dup options[:peer_host] = IPAddr.parse(options[:peer_host]) case options.delete(:protocol) when :tcp options[:server] ? create_tcp_server(options) : create_tcp(options) when :udp options[:server] ? create_udp_server(options) : create_udp(options) end end
Connect to a host over TCP.
@abstract
@option options :peer_host [String,IPAddr] @option options :peer_port [Fixnum] @option options :local_host [String,IPAddr] @option options :local_port [Fixnum] @return [RaptorIO::Socket::TCP]
# File lib/raptor-io/socket/comm.rb, line 103 def create_tcp(options) raise NotImplementedError end
Create a TCP server listening on :local_port
@abstract
@option options :local_host [String,IPAddr] @option options :local_port [Fixnum] @option options :ssl_context [OpenSSL::SSL::Context]
# File lib/raptor-io/socket/comm.rb, line 126 def create_tcp_server(options) raise NotImplementedError end
Create a UDP socket bound to the given :peer_host
@abstract
@option options :peer_host [String,IPAddr] @option options :peer_port [Fixnum] @option options :local_host [String,IPAddr] @option options :local_port [Fixnum]
# File lib/raptor-io/socket/comm.rb, line 115 def create_udp(options) raise NotImplementedError end
Create a UDP server listening on :local_port
@abstract
@option options :local_host [String,IPAddr] @option options :local_port [Fixnum]
# File lib/raptor-io/socket/comm.rb, line 136 def create_udp_server(options) raise NotImplementedError end
Resolves a hostname to an IP address using this comm.
@abstract
@param [String] hostname
# File lib/raptor-io/socket/comm.rb, line 81 def resolve( hostname ) raise NotImplementedError end
Resolves an IP address to a hostname using this comm.
@abstract
@param ip_address [String]
# File lib/raptor-io/socket/comm.rb, line 90 def reverse_resolve( ip_address ) raise NotImplementedError end