class OSC::TCP::SendingSocket

A wrapper around an open TCP socket providing SLIP encoding for outbound messages.

Public Class Methods

new(socket) click to toggle source
# File lib/qlab-ruby/core-ext/osc-ruby/sending_socket.rb, line 6
def initialize socket
  @socket = socket
end

Public Instance Methods

send(msg) click to toggle source

send SLIP encoded OSC messages

# File lib/qlab-ruby/core-ext/osc-ruby/sending_socket.rb, line 11
def send msg
  @socket_buffer = []

  enc_msg = msg.encode

  send_char CHAR_END

  enc_msg.bytes.each do |b|
    case b
    when CHAR_END
      send_char CHAR_ESC
      send_char CHAR_ESC_END
    when CHAR_ESC
      send_char CHAR_ESC
      send_char CHAR_ESC_ESC
    else
      send_char b
    end
  end

  send_char CHAR_END

  flush
end

Private Instance Methods

flush() click to toggle source
# File lib/qlab-ruby/core-ext/osc-ruby/sending_socket.rb, line 38
def flush
  @socket.send @socket_buffer.join, 0
end
send_char(c) click to toggle source
# File lib/qlab-ruby/core-ext/osc-ruby/sending_socket.rb, line 42
def send_char c
  @socket_buffer << [c].pack('C')
end