microcx has asked for the wisdom of the Perl Monks concerning the following question:
Hi, monks! Another guy suffering from debugging TCP server-client pair. Please shed some light!
I'm using
print $socketHandle "$longHexString"it works fine, but if I use:
pack("H*",$longHexString)and send those packed raw bytes, my poor server just sends 483 bytes out of 796 bytes to my client.
I've tried the autoflush trigger and use EOT as $\, but they just don't work. Here are code for both the server and client, thanks in advance :-)
#!/usr/bin/perl -w use strict; use warnings; use IO::Socket; my $server_port=29000; my $server = IO::Socket::INET->new(LocalPort =>$server_port, Type=>SOCK_STREAM, Reuse=>1, Listen=>10 )# or SOMAXCONN or die "Couldn't be a tcp server on port $server_port : $@\n"; while (my $client = $server->accept()) { # $client is the new connection $client-> autoflush(1); print "$client\n"; my $dataPrint=<$client>; print "$dataPrint"; my $lig="0100031cc0000110010000160000000000000000000001074000004530303 +9362d736573736d67722e73746172656e742d67792d3032313b343736353239383230 +3b3533363832313038383b35313232333363382d36303032000000000001084000002 +3303039362d736573736d67722e73746172656e742d67792d30323100000001284000 +001b73746172656e746e6574776f726b732e636f6d000000011b4000001363616d696 +16e742e636f6d00000001024000000c00000004000001cd4000001633323235314033 +6770702e6f72670000000001a04000000c000000010000019f4000000c00000000000 +000014000000c766f6964000001164000000c5109e66a000000374000000cd4ccb248 +000001bb40000028000001c24000000c00000000000001bc400000133333373631333 +33739323300000001bb4000002c000001c24000000c00000001000001bc4000001732 +303832303130303134323032323100000001c74000000c00000001000001ca4000002 +c000001cb4000000c00000000000001cc400000183335343937323035303032323338 +303100000369c0000180000028af0000036ac0000174000028af00000002c00000100 +00028af1fc1b44700000003c0000010000028af00000000000004cbc0000012000028 +af00010a260f0b000000000005c0000025000028af39392d313339323146373339364 +53845383734383235383738000000000004ccc0000012000028af000150d6f4010000 +0000034fc0000012000028af000150d6f2c0000000000008c0000011000028af32303 +832300000000000000ac000000d000028af350000000000001ec000001b000028af6d +6d73626f75796774656c2e636f6d000000000cc000000d000028af300000000000000 +dc0000010000028af3038303000000012c0000011000028af32303832300000000000 +0017c000000e000028af40200000000003ec4000002c6d6d73626f75796774656c5f7 +2756c65626173655f464e425f4d6f6e74686c795f34474200000016c0000014000028 +af0102f8025097b00e00000015c000000d000028af01000000000004dfc0000010000 +028af00000000"; print "length ago:".length($lig)."\n"; my $lig1=pack("H*",$lig); print "length now:".length($lig1)."\n"; #my $lig2=unpack("H*",$lig1); #print "length now:".length($lig2)."\n"; #select ($client); #$\=chr(4); print $client $lig1."\n"; #print $client $lig2."\n"; #$client->syswrite($lig); #$client->flush(); } close($server);
client:
#!/usr/bin/perl -w use IO::Socket; use strict; my $remote_host='bt1svmi6'; my$remote_port=29000; my $socket = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => $remote_port, Proto=> "tcp", Type=> SOCK_STREAM) or die "Couldn't connect to $remote_host:$remote_port : $@\n"; #$wantToSpeak=0; # ... do something with the socket my $lig="Need for Diameter!\n"; print $socket $lig; my $answer = <$socket>; # and terminate the connection when we're done print "I have the response\n"; close($socket); chomp ($answer); print $answer; $answer=unpack("H*",$answer);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TCP server sends just part of my packet
by hdb (Monsignor) on Apr 16, 2013 at 12:05 UTC | |
by roboticus (Chancellor) on Apr 16, 2013 at 12:30 UTC | |
by microcx (Initiate) on Apr 16, 2013 at 13:02 UTC | |
by microcx (Initiate) on Apr 16, 2013 at 12:57 UTC | |
by hdb (Monsignor) on Apr 16, 2013 at 12:59 UTC |