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

N

nephish

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top