How to have socket server always listen but also initiate a connection

Hey all.

We are working with cell radios that have a dynamic ip address that
last a few hours.
I need a socket server that can receive messages from these, but i
also need to be able to initiate a connection to them on the same ip
and port.

here is what i have so far, and it is working to bring data in from
the radios.

require ‘socket’
server =‘’, 1411)

loop {

Thread.start(server.accept) do |client|
while line = client.gets

  # now we make a text string for this
  d_out = ""
  line.split("").each do |i|
      d_out += "#{i[0]}-"


  # testing only
  # data_line = "you said #{line} - total packet length =

# client.puts data_line

  # puts data_line


i am able to send the data right back to the radio correctly, but i
need a way to send info back maybe an hour later or so.

thanks for any tips on this.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs