I wrote a socket program using ruby under windows, the main loop of this
program is:
begin
server = TCPServer.new(‘127.0.0.1’, port)
rescue Exception => e
puts e.message
exit
end
while session = server.accept do
Thread.new do
Client.new(session).run
end
end
It runs smoothly. However I found a strange problem. If I run another
program (not written in Ruby) using the same port, that program will
take control of the port, and my program is “over-ruled”! However, if
the other program runs first, and then I run my ruby one, the ruby
program print out error message that it can’t bind the port.
I don’t know why ruby’s socket is so polite? Wondering…
Does your other program also bind to localhost, or does it bind to 0.0.0.0
(INADDR_ANY, meaning ‘all interfaces’)?
Maybe Windows is broken in allowing program A to bind to 127.0.0.1, then
when program B binds to 0.0.0.0 it takes over 127.0.0.1 as well. Just a
guess.
But try changing your Ruby program to:
server = TCPServer.new(‘0.0.0.0’, port)
Regards,
Brian.
···
On Mon, Jul 28, 2003 at 08:22:49PM +0900, Xiangrong Fang wrote:
begin
server = TCPServer.new(‘127.0.0.1’, port)
rescue Exception => e
puts e.message
exit
end
while session = server.accept do
Thread.new do
Client.new(session).run
end
end
It runs smoothly. However I found a strange problem. If I run another
program (not written in Ruby) using the same port, that program will
take control of the port, and my program is “over-ruled”! However, if
the other program runs first, and then I run my ruby one, the ruby
program print out error message that it can’t bind the port.
It runs smoothly. However I found a strange problem. If I run another
program (not written in Ruby) using the same port, that program will
take control of the port, and my program is "over-ruled"! However, if
the other program runs first, and then I run my ruby one, the ruby
program print out error message that it can't bind the port.
The other program use SO_REUSEADDR, you have the explanation in
Maybe Windows is broken in allowing program A to bind to 127.0.0.1, then
when program B binds to 0.0.0.0 it takes over 127.0.0.1 as well. Just a
guess.
But try changing your Ruby program to:
server = TCPServer.new(‘0.0.0.0’, port)
Both the ruby program and the other program listen ONLY on 127.0.0.1.
How can I use the binding mode in Ruby? I use TCPServer. which seems is
a very high level wrapper. I also tried to look for TCPServer.rb, but I
can’t find it. Seems that the TCPServer class is a build in module of
Ruby intepretor.
How can I use the binding mode in Ruby? I use TCPServer. which seems is
a very high level wrapper. I also tried to look for TCPServer.rb, but I
can't find it. Seems that the TCPServer class is a build in module of
Ruby intepretor.
How can I use the binding mode in Ruby? I use TCPServer. which seems is
a very high level wrapper. I also tried to look for TCPServer.rb, but I
can’t find it. Seems that the TCPServer class is a build in module of
Ruby intepretor.
such that the control over selection, property population, and
execution of a command is handled by one logical controller, and
forwarding to a view renderer by another, and both are keyable from the
URI (such as one like the above). I have done this in Java via
servlets, but as I want it for a personal project - I would prefer to
find a Ruby solution, and before I make one… best to make sure I am
not duplicating effort.
The command and view controllers are metadata driven (config file or
script (really a script I guess, this is a scripting language after
all, no recompilation needed =)
Anyone know of anything that already does this in the Ruby world? i
hate to be implementing yet-another-web-application-framework.
such that the control over selection, property population, and
execution of a command is handled by one logical controller, and
forwarding to a view renderer by another, and both are keyable from the
URI (such as one like the above).
Except that Struts won’t do what I want - it keys the View control off
of results of Action execution instead of the URI, hacking it pull
effectively two actions (in its parlance) out of the URI isn’t worth
the effort, so I use Cocoon or a home rolled servlet to do this in the
Java world.
Will take a look at ruby-waf, but it seems to be advertised as a Struts
clone =/
-Brian
···
On Tuesday, July 29, 2003, at 05:31 AM, Rasputin wrote: