kamrul has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a perl script for communicating with android GCM CCS. My script looks like the below:
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">MTI2MjAwMzQ3OTMzQHByb2plY3RzL +mdjbS5hb mFTeUIzcmNaTmtmbnFLZEZiOW1oekNCaVlwT1JEQTJKV1d0dw==</auth>'; if(!<$client>){ print "Auth error\n"; } else { print <$client>; }
After writing the first request on the socket I get response as expected from google server. And I cant print the server response using print But, I dont get any response after writing the second request. It seems like the connection gets closed after the first request and response or something. How do I send multiple request through open TLS connection and receive server responses ?

Replies are listed 'Best First'.
Re: Perl IO::Socket::SSL persistent TCP connection
by Anonymous Monk on May 01, 2015 at 22:15 UTC
    if(!<$client>){ print "Auth error\n"; } else { print <$client>; }

    That is a weird way to use readline

      Hi, Thanks for your reply. I get the below while having debug on.
      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:xm +pp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</me +chanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>Au +th error DEBUG: .../IO/Socket/SSL.pm:1500: free ctx 145780168 open=145780168 DEBUG: .../IO/Socket/SSL.pm:1508: OK free ctx 145780168
      Someone told me the server is closing the connection as Im using print <$client> as it will try to read all lines from the socket and all lines is only finished once the server has closed the connection. Then what is the best way to send request to the server and waiting for the response, checking the response and sending a response back ? (using IO::Socket::SSL). Can anyone give me an example ?