From: Logan Capaldo Date: 2006-08-09T01:27:26+09:00 Subject: Re: Signaling Ruby from C/C++ On Aug 8, 2006, at 8:28 AM, Francis Cianfrocca wrote: > > 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/. > It ain't perfect, but: require 'timeout' require 'socket' port = 2200 server = nil Timeout::timeout(2.0) do begin begin server = TCPServer.new( port ) rescue Errno::EADDRINUSE port += 1 retry end rescue Timeout::Error puts "Gave up trying to get a port" exit 1 end end client = TCPClient.new( 'localhost', port )