Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

My server doesnt get all the data sent by the client application

by Rad (Novice)
on May 10, 2013 at 16:30 UTC ( #1032982=perlquestion: print w/ replies, xml ) Need Help??
Rad has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i wrote this basic perl script to listen for connections, get the data sent on the socket. the problem i have is, I only get some of that data. here is my code-

use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => '168.159.250.206', LocalPort => '5988', Proto => 'tcp', Listen => 500, Reuse => 1, ); $sock->sockopt(SO_RCVBUF, 1500); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); my $a = ""; while(<$new_sock>) { $new_sock->autoflush(1); print $_; $a = $a.$_; } print "a is $a"; #close($sock);

I took a network trace of my application client and server and i see that on the same port, client sends half the data and then sends the next half of data. what i get is in the below second half of data, i only get "<?xml version="1.0" encoding="UTF-8"?>"

<?xml version="1.0" encoding="UTF-8"?>.<CIM CIMVERSION="2.0" DTDVERSION="2.0"><MESSAGE ID="155178" 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>

Comment on My server doesnt get all the data sent by the client application
Download Code
Re: My server doesnt get all the data sent by the client application
by vsespb (Hermit) on May 10, 2013 at 17:23 UTC
    Works fine for me. When script ran on Linux, and client is linux telnet. Have you tried different clients?

      This is the server script that i am running on a windows machine. My application running on a linux box comes and tries to send a request and my server script listens for requests and then should respond back.

      I dont know why i dont get the whole request.

      Is there a way, i can send the snapshot of the network capture?

      Because, when my application sends the request to a real server, it sends it as 2 packets on the same socket.

        So, your server is on Windows and client on linux. Try adding
        local($/) = "\012";
        in the beginning of your code. http://perldoc.perl.org/perlport.html#Newlines
Re: My server doesnt get all the data sent by the client application
by Anonymous Monk on May 10, 2013 at 22:33 UTC

    readline waits for a trailing newline

    A better protocol would start with the number of bytes of the message, so that you can use read until you read that number of bytes

Re: My server doesnt get all the data sent by the client application
by jakeease (Friar) on May 12, 2013 at 08:33 UTC

    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);

      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);

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032982]
Approved by Old_Gray_Bear
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-12-27 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls