D
Doug Jolley
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'
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<request>
<category>client</category>
<action>Login</action>
<params>
<param name="clid">135610</param>
<cltrid>135610A1276479316B171</cltrid>
<chksum>4bdee845b6e6dc67754b038f2b08bf74</chksum>
</params>
</request>
_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
<?php
$login_request=<<< _ALTO
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<request>
<category>client</category>
<action>Login</action>
<params>
<param name="clid">135610</param>
<cltrid>135610A1276479316B171</cltrid>
<chksum>4bdee845b6e6dc67754b038f2b08bf74</chksum>
</params>
</request>
_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);
?>
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'
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<request>
<category>client</category>
<action>Login</action>
<params>
<param name="clid">135610</param>
<cltrid>135610A1276479316B171</cltrid>
<chksum>4bdee845b6e6dc67754b038f2b08bf74</chksum>
</params>
</request>
_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
<?php
$login_request=<<< _ALTO
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<request>
<category>client</category>
<action>Login</action>
<params>
<param name="clid">135610</param>
<cltrid>135610A1276479316B171</cltrid>
<chksum>4bdee845b6e6dc67754b038f2b08bf74</chksum>
</params>
</request>
_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);
?>