From: Joel VanderWerf Date: 2006-06-21T02:04:45+09:00 Subject: Re: How to get the response from a UDP socket. Francis Cianfrocca wrote: > Hamid Rasoulian wrote: >> sock.bind($IP1 , $port1) > ... >> server.bind(nil, $port1) > >>>> Two sockets can't bind to the same port. This raises the error:<<< > > > They're on two different machines, note the two different IP addresses. > (Unless he's multihomed.). There are other problems with this code anyway. Look again at OPs code (below). Both sockets, "server" and "sock" are being bound to $port1, and "server" is bound to any address, so this code will raise EADDRINUSE. It happens that way on my linux box, anyway. require 'socket' $port1 = 5000 $IP1 = '10.15.0.21' $port2 = 15000 $IP2 = '10.15.0.66' sock = UDPSocket.open sock.bind($IP1 , $port1) sock.connect($IP2 , $port2) server_thread = Thread.start do server = UDPSocket.open server.bind(nil, $port1) 2.times { p server.recvfrom(64) } end # now I send the message to device. sock.send (" my UDP message", 0) # and immediately I enter this command server_thread.join > He doesn't show the line that sends the data from the client to the server, > and he also doesn't show the client code that receives the reply. As far as > I can tell, he's trying to send data from the client to a server port which > is different from the one the server is listening on. And yet, he says the > server receives the request. So something is missing in the code sample. I think all of the above code is running on the "client" side (despite the "server" variable name), and this program is talking to some other socket that may not even be controlled by ruby code. So this is the complete client code, with all the needed send and recv calls. It might work without the sock.bind call. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407