我正在编写一个用于与android GCM CCS通信的perl脚本。我的脚本如下所示:
use IO::Socket::SSL;
my $client = IO::Socket::SSL->new('gcm.googleapis.com:5236')
or die "error=$!, ssl_error=$SSL_ERROR";
print $client '<stream:stream to="gcm.googleapis.com" version="1.0"
#xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams"/>';
print <$client>;
print $client '<auth mechanism="PLAIN"
xmlns="urn:ietf:params:xml:ns:xmpp-sasl">MTI2MjAwMzQ3OTMzQHByb2plY3RzLmdjbS5hb
mFTeUIzcmNaTmtmbnFLZEZiOW1oekNCaVlwT1JEQTJKV1d0dw==</auth>';
if(!<$client>){
print "Auth error\n";
} else {
print <$client>;
}
在套接字上写完第一个请求后,我得到了谷歌服务器的预期响应。我无法使用print打印服务器响应 但是,在写完第二个请求后,我没有得到任何回复。在第一次请求和响应之后,似乎连接被关闭了。如何通过开放TLS连接发送多个请求并接收服务器响应?
更新
如果我打开调试
,我会得到以下内容DEBUG: .../IO/Socket/SSL.pm:1464: new ctx 145780168
DEBUG: .../IO/Socket/SSL.pm:332: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:334: socket connected
DEBUG: .../IO/Socket/SSL.pm:347: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:390: Net::SSLeay::connect -> 1
DEBUG: .../IO/Socket/SSL.pm:445: ssl handshake done
write_all VM at entry=vm_unknown
written so far 124:124 bytes (VM=vm_unknown)
write_all VM at entry=vm_unknown
written so far 188:188 bytes (VM=vm_unknown)
got 147:0 bytes (VM=vm_unknown).
got 197:147 bytes (VM=vm_unknown).
got 0:344 bytes (VM=vm_unknown).
got 0:0 bytes (VM=vm_unknown).
DEBUG: .../IO/Socket/SSL.pm:1201: SSL read errorerror:00000000:lib(0):func(0):reason(0)
<stream:stream from="gcm.googleapis.com" id="626DAFBE58C7FD0D" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>Auth error
DEBUG: .../IO/Socket/SSL.pm:1500: free ctx 145780168 open=145780168
DEBUG: .../IO/Socket/SSL.pm:1508: OK free ctx 145780168
答案 0 :(得分:2)
DEBUG:... / IO / Socket / SSL.pm:1201:SSL读错误错误:00000000:lib(0):func(0):reason(0)
服务器关闭了连接。如果服务器决定关闭连接,则无法保持连接打开并发送更多内容。收盘可能与您收到的Auth错误有关。
此外:
print <$client>;
您正在列表上下文中调用<>
运算符。这意味着它将尝试从套接字读取所有行。由于所有行只在服务器关闭连接后完成(这是TCP工作的方式,与TLS无关),所以你有效地等到服务器关闭。