oddities with select

J

Jim Marshall

Ben Giddings said:
I'm trying to use Ruby to talk to an network application, and noticed
something odd. Using ethereal, I can see that the server is returning a
newline to the client, however my Ruby code, calling select([socket],
[], [], 0.1) repeatedly for 5 seconds never seems to know that there's
data to be read.

This works for me, unless I am misunderstanding what you are trying
to do:

---- test_server.rb ------
#!/usr/bin/ruby -w

require 'socket'
a = TCPServer.new("localhost", 9999).accept
loop do
a.puts
sleep 3
end
--------------------------

and then

---- test_client.rb ------
#!/usr/bin/ruby -w

require 'socket'

a = TCPSocket.new("localhost", 9999)
loop do
if select([a], [], [], 0.1)
p a.read(1)
end
end
--------------------------

Having already started the server, the client prints out a "\n" as
soon as it is started, and then every 3 seconds thereafter. Is it
possible that your code is actually getting held up somewhere else,
so that it's not even hitting the select()? For example, if I were to
change the "a.read(1)" in the client there to just "a.read", then it
would get stuck there until the socket was closed.
 

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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top