class Gorsse::Connection

This class hide the ZMQ library but it is closely tied to it.

Constants

CONNECTION_MODE
ZCTX

Public Class Methods

new(url, mode: :push, method: :connect) click to toggle source

Open a connection to an URL. You can act as a server or as a client by tunning the 'server' parameter.

# File lib/gorsse/connection.rb, line 19
def initialize(url, mode: :push, method: :connect)
  @zmq_socket = ZCTX.socket(CONNECTION_MODE[mode])
  @zmq_socket.__send__(method, url)
  puts '%s with %s to %s' % [method, mode, url]
end

Public Instance Methods

close() click to toggle source
# File lib/gorsse/connection.rb, line 36
def close
  @zmq_socket.close
end
receive(flags: 0) click to toggle source
# File lib/gorsse/connection.rb, line 30
def receive(flags: 0)
  message = ''
  @zmq_socket.recv_string(message, flags)
  message
end
send(string, flags: 0) click to toggle source
# File lib/gorsse/connection.rb, line 25
def send(string, flags: 0)
  puts 'Sending: %s' % string
  @zmq_socket.send_string(string, flags)
end