From: Patrick Toomey Date: 2006-09-07T06:33:58+09:00 Subject: Re: Total newbie, but I think I found a bug in Socket? On Sep 6, 2006, at 8:15 AM, Daniel Martin wrote: > Daniel Martin writes: > >> Tell me, does this ruby script work on your two environments? >> >> # In one script, start this first >> require 'socket' >> include Socket::Constants >> sockaddrinfo = Socket.getaddrinfo( 'localhost', 2200, AF_INET, >> SOCK_STREAM )[0] >> socket = Socket.new( *sockaddrinfo[4..6] ) >> sockaddr = Socket.pack_sockaddr_in( sockaddrinfo[1], >> sockaddrinfo[3] ) >> socket.bind( sockaddr ) >> socket.listen( 5 ) >> client, client_sockaddr = socket.accept >> puts "The client said, '#{client.readline.chomp}'" >> client.puts "Hello from script one!" >> socket.close > > > Actually, I made a slight error here, according to the documentaion of > getaddrinfo. That "sockaddr =" bit should be: > > sockaddrinfo = Socket.getaddrinfo( 'localhost', 2200, AF_INET, > SOCK_STREAM, nil, AI_PASSIVE )[0] > > In this context (when we're binding to a specific IP address) it > doesn't matter, but if you're re-using this code to bind to the "any" > address, you'll want that AI_PASSIVE bit in there. (You'll also want > to replace 'localhost' with nil) > > This script ran perfectly. Thanks for all your help. When I get some time I'll sit down to actually process what your above script is actually doing :-) Thanks, Patrick