Problem. I set up a UDP socket connection. I send a message to the
socket, and the destination device receives the message correctly and
act upon it, so far so good, but the destination device would send a
message back to the host and I do not know how to capture that message
and print the message.
Here is what I do, the local port is $port1 and $IP1 and the destination
assume to be $port2 and $IP2
I do the following:
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
But nothing happens. And no receiving message is being printed out,
while I am sure the device has sent some message back.
I just do not understand the receiving part of it.
Can any body help me with it.