From: Doug Jolley Date: 2010-06-17T10:10:53+09:00 Subject: Socket Problems I want to use a Ruby script to connect to a vendor API. I have 2 problems: 1) It takes almost a minute to establish a connection; and, 2) after the connection is finally established, no data is returned in response to any requests. My test script which exhibits these problems is appended as Exhibit A. As part of my investigation into these problems, I put together a comparable PHP script. It is shown in Exhibit B and it works perfectly (i.e., it exhibits neither of these problems). In both scripts actual values are used for 'ip' and 'port'. I'm really hoping that someone can tell me what I need to do to get my Ruby script working properly. TIA. ... doug Exhibit - Malfunctioning Ruby Script #!/opt/ruby-enterprise-1.8.6-20090610/bin/ruby require 'socket' login_request=<<'_ALTO' client Login 135610 135610A1276479316B171 4bdee845b6e6dc67754b038f2b08bf74 _ALTO socket=TCPSocket::new('ip','port') puts("Connect:\n"+socket.read()+"\n\n") socket.print(login_request) puts("Login:\n"+socket.read()) response=socket.read() puts(response) socket.close Exhibit B - Properly Functioning Comparable PHP Script client Login 135610 135610A1276479316B171 4bdee845b6e6dc67754b038f2b08bf74 _ALTO; $fp=fsockopen("ip",port); print("Connect:\n".fread($fp,1000)."\n\n"); fwrite($fp,$login_request); print("Login:\n".fread($fp,1000)); fclose($fp); ?> -- Posted via http://www.ruby-forum.com/.