Simon, that was a nyyyyz idea to use a TCP socket, as ugly as it is,
just to work around Windows' even-uglier-ness. Here's a simpler version
of your code (notice I commented out the server.close, which may cause
problems on some platforms). This code works on Linux. Haven't tested on
Windows. You don't need a thread because after the server socket calls
listen(2), the client can call connect(2) any time, and the
partially-completed connection will be held in the kernel as long as
necessary until the server calls accept(2). These events do not need to
be synchronous.
(I substituted Ruby's more-cooked TCP socket objects just to make it
simpler, even though under the covers these objects are not really
related to the Socket objects you used. In this case it doesn't seem to
matter- maybe it does on Windows.)
#---------------------------
require 'socket'
server = TCPServer.new( 'localhost', 2200 )
wr = TCPsocket.new( 'localhost', 2200 )
rd = server.accept
#server.close
Thread.new {
loop do
puts rd.read(1)
end
}
loop do
sleep 1
wr.write '+'
end
#----------------------------
What's ugly about this of course is that you can only run this process
once at a time because of the hardcoded port. I *know* for sure that I
have solved this problem in the past with Windows pipes, because an
early version of EventMachine used exactly that technique. I'll have to
dig through the source-code archives and find it.
--
Posted via http://www.ruby-forum.com/.