From: Anukul Singhal Date: 2009-02-04T02:02:01+09:00 Subject: Re: Socket: Getting EADDRNOTAVAIL in bind method Gary, 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: require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) puts socket.inspect sockaddr = Socket.pack_sockaddr_in(5555, '143.91.34.205') puts sockaddr.inspect (returns "\002\000\025\263\217[\"\315\000\000\000\000\000\000\000\000") 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 terminated puts receive.inspect 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 480) Thanks, Anukul Anukul Singhal wrote: > Gary, thanks for your reply. 114.23.42.42 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? > > Thanks, > Anukul > > Gary Wright wrote: >> On Feb 2, 2009, at 4:50 PM, Anukul Singhal wrote: >>> >>> In the last method bind, getting the following error: >>> >>> Test.rb:50:in `bind': The requested address is not valid in its >>> context. >>> - 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 114.23.42.42 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. >> >> Gary Wright -- Posted via http://www.ruby-forum.com/.