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.
so…

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

require ‘socket’
server = TCPServer.open(‘192.168.1.113’, 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]}-"
  end

  create_message_from_socket_data(d_out)


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

#{line.size}"
# client.puts data_line

  # puts data_line
end

end
}

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.
sk

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