> -----Original Message-----
> From: Francis Cianfrocca [mailto:garbagecat10 / gmail.com]
> Sent: Wednesday, June 21, 2006 3:14 AM
> To: ruby-talk ML
> Subject: Re: How to get the response from a UDP socket.
>
> >
> > >>>
> > That's a good point, but the OP seemed to have a fixed port
> in mind that
> > the remote socket would reply to (port 5000). Maybe the
> remote process
> > doesn't use the sender's address. I can only guess...
> > <<<
>
>
> Revised version that assumes the server will reply to port 5000:
>
> u = UDPSocket.new
> u.bind( client_ip_address, 5000 ) # This is the only change.
> u.send( "UDP Message", 0, server_ip_address, server_port)
> response = u.recv(4096)
>
>
> Observe, you can't specify nil as the bind-address, as the OP
> did.

What makes you say that? I'm using this code in something, and it works
perfectly:

socket=UDPSocket.new
socket.bind('',500)
socket.connect("172.16.35.131",500)
socket.send(payload,0)

You don't need to bind() to send() but I needed to fix the source port at
500 for stuff to work. Bind()ing to a specific address seems to actually
causes weird connect() errors sometimes if you have lots of interfaces. It's
unusual for the server to ignore the client source port when responding, but
certainly not unheard of.

Cheers,

ben