class Lwes::Emitter
Emit LWES events to a UDP endpoint
Constants
- DEFAULT_SOCIKET_OPTIONS
Attributes
socket[RW]
socket_options[RW]
Public Class Methods
new(options={})
click to toggle source
Creates a new {Lwes::Emitter}. @param [Hash] options @option options [String] :host UDP host address, defaults to 127.0.0.1 @option options [String, Number] :port UDP port, defaults to 12345 @option options [Number] :address_family, Address family of the socket, defaults to Socket::AF_INET
# File lib/lwes/emitter.rb, line 19 def initialize(options={}) self.socket_options = DEFAULT_SOCIKET_OPTIONS.merge(options) self.socket = UDPSocket.new(@socket_options[:address_family]) socket.connect(@socket_options[:host], @socket_options[:port]) end
Public Instance Methods
emit(event)
click to toggle source
Emits specified event @param [Lwes::Event] event The event to send @return [Number] the number of bytes sent
# File lib/lwes/emitter.rb, line 28 def emit(event) buffer = StringIO.new event.write(buffer) buffer.rewind socket.write(buffer.read) end