Ruby socket programming

Hello I am trying to write a simple ruby socket program. I am trying
to communicate to a device that once I establish a TCPSocket
connection I can pass it sql commands and it will return me data.
Here is what I have been trying.

require ‘socket’
begin
t = TCPSocket.new(‘192.168.0.71’, 8080)
rescue
puts “error: #{$!}”
else
# … do something with the socket
t.write(“select read_count from tag_id”)
answer = t.gets
puts answer
# and terminate the connection when we’re done
t.close
end

My answer contains nothing, so I know I must be doing something
wrong. The device I am communication to is a ThingMagic RFID M4 and
the manufacturer assures me that once a TCP Socket connection is
established that passing queries as above will give back data. I know
that the device is working from other tests. Any help would be
appreciated.
Thanks
Larry

On May 23, 2007, at 11:54 AM, monarailguy42 wrote:

else
# … do something with the socket
t.write(“select read_count from tag_id”)

did you try with a t.flush or maybe a t.puts("…")?..

On 5/23/07, monarailguy42 [email protected] wrote:

# ... do something with the socket

t.write(“select read_count from tag_id”)
answer = t.gets

How the device knows the data you wrote is the complete query?
Shouldn’t you send some mark (newline, ‘;’ or something like that) to
let the device knows where the query ends?

Dear All

----- Original Message -----
From: “Luis P.” [email protected]
To: “ruby-talk ML” [email protected]
Sent: Wednesday, May 23, 2007 11:10 PM
Subject: Re: ruby socket programming

On 5/23/07, monarailguy42 [email protected] wrote:

# ... do something with the socket

t.write(“select read_count from tag_id”)
answer = t.gets

How the device knows the data you wrote is the complete query?
Shouldn’t you send some mark (newline, ‘;’ or something like that) to
let the device knows where the query ends?

I Tried with socket server script from

and the client is :
—Start----
#!/usr/local/bin/ruby
require ‘socket’
aa=0
loop do
aa = aa+1
sock = TCPSocket.new(‘127.0.0.1’, 20000)
sendit = “We send #{aa}”
sock.send(sendit,0)
str = sock.recv(100)
puts ‘we received #{str}’
sock.close
sleep (1)
end
—Stop----

Work fine for me

But … i think it’ll be better if the device can act as client, and
always
send all data in comma delimeted , so the server (we , user) can just
wait
for data and parse received data easily.
Just like what Barcode reader do with keyboard port

Sincerely
-bino-