From: Ernest Ellingson Date: 2001-01-10T08:10:37+09:00 Subject: [ruby-talk:8966] Re: sockaddr Thanks, I tried cheating while I was looking around. I opened a TCPSocket, used getpeername which returns the sockaddr of the other side of the the TCPSocket. Used that for connection. eg: x=TCPSocket.new('localhost',81) z=x.getpeername x.close ... At 06:49 1/10/2001 +0900, you wrote: >Ernest Ellingson writes: > > > Does anyone know where I can find an example of building a sockaddr > > structure and mapping it to an opaque binary string. I know I should be > > using a higher level socket class but the server I'm talking to drops the > > connection immediately after I do a puts on a TCPsocket. I want to do a > > put on the socket and then remain connected, indefinitely for information > > from the server. I've seen an example of this in Python and in Perl. It > > looks like I have to create a new Socket object. The connect requires a > > socaddr structure contained in a string. > >Have a look at ruby-talk:8634. Basically it looks like > > sock = Socket.open(Socket::AF_INET, Socket::SOCK_STREAM, 0) > n = Socket.gethostname("localhost") > sockaddr = [Socket::AF_INET, 3456, n[3], 0, 0].pack("snA4NN") > sock.bind(sockaddr) > > >Regards > > >Dave