<commit_before>require 'rbczmq'

def query(context, address, port)

  dealer = context.socket(:DEALER)
  dealer.identity = "katzenbus"
  server = "tcp://192.168.1.#{address}:#{port}"
  puts "Query hello server at: #{server}"

  dealer.rcvtimeo = 5_000
  dealer.sndtimeo = 5_000
  dealer.connect(server)

  message = "Hello"
  puts "#{server} < #{message.inspect}"
  dealer.send(message)

  msg = dealer.recv
  puts "#{server} > '#{msg}'"
  dealer.close

end

context = ZMQ::Context.new
socket  = context.socket(:SUB)
socket.rcvhwm = 20
socket.rcvtimeo = 5_000
socket.subscribe ""

pattern = /^(\d{1,3}):(\d{1,5})$/

for ip in [9, 25]
  address = "tcp://192.168.1.#{ip}:6665"
  rc = socket.connect(address)
end

while true
  msg = socket.recv

  if msg
    result = pattern.match(msg.to_s)
    puts "Service discovered: #{msg.inspect}"
    query(context, result[1], result[2]) if result
  else
    puts "No message"
  end<commit_msg>Avoid timouts for reads on discovery socket<commit_after>require 'rbczmq'

def query(context, address, port)

  dealer = context.socket(:DEALER)
  dealer.identity = "katzenbus"
  server = "tcp://192.168.1.#{address}:#{port}"
  puts "Query hello server at: #{server}"

  dealer.rcvtimeo = 5_000
  dealer.sndtimeo = 5_000
  dealer.connect(server)

  message = "Hello"
  puts "#{server} < #{message.inspect}"
  dealer.send(message)

  msg = dealer.recv
  puts "#{server} > '#{msg}'"
  dealer.close

end

context = ZMQ::Context.new
socket  = context.socket(:SUB)
socket.rcvhwm = 20
socket.subscribe ""

pattern = /^(\d{1,3}):(\d{1,5})$/

for ip in [9, 25]
  address = "tcp://192.168.1.#{ip}:6665"
  rc = socket.connect(address)
end

while true
  msg = socket.recv

  if msg
    result = pattern.match(msg.to_s)
    puts "Service discovered: #{msg.inspect}"
    query(context, result[1], result[2]) if result
  else
    puts "Empty discovery message"
  end
{'fraction_non_alphanumeric': 0.16356877323420074, 'fraction_numerical': 0.04142326075411577, 'mean_word_length': 3.757575757575758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3547383', 'n_tokens_mistral': 748, 'n_tokens_neox': 722, 'n_words': 162}