in reply to My server doesnt get all the data sent by the client application

I tweaked a couple things; can't really test except simple localhost things.

#!/usr/bin/perl -w use strict; use IO::Socket; my $sock = IO::Socket::INET->new( #LocalHost => '168.159.250.206', LocalPort => '80', Proto => 'tcp', Listen => SOMAXCONN, #whatever the + system max is Reuse => 1, ); #$sock->sockopt(SO_RCVBUF, 1500); die $@ unless $sock; # $@ will tell you the error message # my $new_sock = $sock->accept(); # my $new_sock; my $a = ""; my $data = ""; while(my $new_sock = $sock->accept()) { $data = <$new_sock>; #$new_sock->autoflush(1); $| = 1; print $data; $a .= $data; print $a; $| = 0; } print "a is $a"; #close($sock);
  • Comment on Re: My server doesnt get all the data sent by the client application
  • Download Code

Replies are listed 'Best First'.
Re^2: My server doesnt get all the data sent by the client application
by Rad (Novice) on May 13, 2013 at 15:39 UTC

    I was working on something else and gone for an hour and i see that i get all of the 2nd buffer. Not sure, why it took so long to get the data. I changed one thing in the code below

    #!/usr/bin/perl -w local($/) = "\012"; use strict; use IO::Socket; my $sock = IO::Socket::INET->new( #LocalHost => '168.159.250.206', LocalPort => '5988', Proto => 'tcp', Listen => SOMAXCONN, #whatever the + + system max is Reuse => 1, ); #$sock->sockopt(SO_RCVBUF, 1500); die $@ unless $sock; # $@ will tell you the error message # my $new_sock = $sock->accept(); # my $new_sock; my $a = ""; my $b = ""; my $data = ""; while(my $new_sock = $sock->accept()) { while(<$new_sock>) {$b = $b.$_; } print $b; #$new_sock->autoflush(1); $| = 1; print $data; $a .= $data; print $a; $| = 0; } print "a is $a"; #close($sock);
Re^2: My server doesnt get all the data sent by the client application
by Rad (Novice) on May 13, 2013 at 16:27 UTC

    Do you think I cant get an xml content from $_? I know my program has received the below data.its in xml format. Would that be contributing to the problem?

    <CIM CIMVERSION="2.0" DTDVERSION="2.0"><MESSAGE ID="425381" PROTOCOLVERSION="1.0"><SIMPLEREQ><IMETHODCALL NAME="EnumerateInstances"><LOCALNAMESPACEPATH><NAMESPACE NAME="root"/><NAMESPACE NAME="brocade1"/></LOCALNAMESPACEPATH><IPARAMVALUE NAME="ClassName"><CLASSNAME NAME="Brocade_Fabric"/></IPARAMVALUE><IPARAMVALUE NAME="LocalOnly"><VALUE>true</VALUE></IPARAMVALUE><IPARAMVALUE NAME="DeepInheritance"><VALUE>false</VALUE></IPARAMVALUE><IPARAMVALUE NAME="IncludeQualifiers"><VALUE>false</VALUE></IPARAMVALUE><IPARAMVALUE NAME="IncludeClassOrigin"><VALUE>true</VALUE></IPARAMVALUE></IMETHODCALL></SIMPLEREQ></MESSAGE></CIM>

      I receive this data almost after an hour. I dont get it. I don't know why we cant get the data right away. I took a network capture and do see the buffers being sent almost instantaneously.

        I got the problem solved, but i dont quite understand why I need to do that. I had to recv data twice to get the 1st and 2nd buffer.

        ..... while(my $new_sock = $sock->accept()) { $|=1; $new_sock->recv($text1, 600); $new_sock->recv($text2, 800); } ....
        Does anyone know when we need to do this? Thanks!