I tried using read, recvfrom, sysread and recv to read the data from the
remote device using socket but my program does not terminate at all.
Here is the code snippet that I am trying:
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in(5555, ‘18.104.22.168’)
puts sockaddr.inspect (returns
puts sockaddr.length # returns 16
sock = socket.connect(sockaddr)
puts sock.inspect # returns 0
receive = socket.read(16) #does not return at all,unless forcefully
Is there something I am missing here, or is there any other way to
retrieve data? Basically, I need to read an image buffer (size 704 x
Anukul S. wrote:
Gary, thanks for your reply. 22.214.171.124 is the address of my device
which is not on my local system. My code works fine till I connect to
the socket, but after that I need to receive buffer from it, for which I
am not able to use the “recvfrom” method. So, I tried to use “bind”
method which did not work (since the device is remote but I am able to
ping it from my local machine and it is also on the same network). Is it
some way I can receive data from the socket after I connect to it?
Gary W. wrote:
On Feb 2, 2009, at 4:50 PM, Anukul S. wrote:
In the last method bind, getting the following error:
Test.rb:50:in `bind’: The requested address is not valid in its
- bind(2) (Errno::EADDRNOTAVAIL)
I think I might be missing something elementary here. If anyone can
please help with it, would be really grateful.
Usually you don’t pick the local address to bind to but instead
let the system pick it. Is 126.96.36.199 your local address or is
the address of the device you are trying to connect to?
If you are trying to bind a local socket to the address of the
remote host/device you’ll get EADDRNOTAVAIL since the address
doesn’t belong to the local host.