Hi - I'm testing some socket receive/send scripts for hl7 messages, and am at my wit's end... I'm hoping someone can help.
The receiver script is running on a linux box. I have the same sender script on both the linux box and an XP machine. I start the listener, and send a long-ish file/message via the sender script on the linux box. I get the expected number of bytes. I send the same file using the same sender script running on the XP box, and it says it only receives 1260 bytes. The files I'm sending consist of text segments strung together with carriage returns (\015) in between. The sender envelopes the file with a vertical tab (\013), then the message, then file sep (\034) and CR (\015).
There is not a carriage return at the place where the windows sender (or maybe the receiver) is truncating. It's just text. I tried (per the chatterbox) using binmode on the windows side, but either I'm not doing it right, or it made no difference. I just cannot get a long block of text to go through from the XP box.
I hope someone can help ??!
Thanks in advance, Chris Hawkins codelady7
Here are the send/receive scripts:
# a simple client using IO:Socket #---------------- use strict; use IO::Socket; my $infile = @ARGV[0]; my $sock; my $HL7 = <>; my $wbytes; my $rbytes = 5120; my $ackback = "no ack received."; open LOGFILE, ">>hl7.log"; my $sock = new IO::Socket::INET (PeerAddr => '192.168.1.210', PeerPort + => 10500, Proto => 'tcp'); $sock or die "no socket :$!"; #print "socket created...\n"; $wbytes = send ($sock, "\013".$HL7."\034\015", 0); recv ($sock, $ackback, $rbytes, 0); print LOGFILE ("File sent: " . $infile . ".\n"); print LOGFILE ("Bytes sent: " . $wbytes . ".\n"); print LOGFILE ("Received ack: " . $ackback . ".\n"); close LOGFILE; close ($sock); ********************************************** # server using IO::Socket #--------------------- use strict; use IO::Socket; open MSGFILE, ">>msgs.dat"; my $sock = new IO::Socket::INET( LocalHost => '192.168.1.210', LocalPort => 10500, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1); $sock or die "no socket :$!"; my($new_sock, $c_addr, $buf); print "listening...\n"; while (($new_sock, $c_addr) = $sock->accept()) { my ($client_port, $c_ip) =sockaddr_in($c_addr); my $client_ipnum = inet_ntoa($c_ip); my $client_host =gethostbyaddr($c_ip, AF_INET); print "got a connection from: $client_host"," [$client_ipnum] "; my $bytesin = 5120; recv($new_sock, $buf, $bytesin, 0); print "length is: ". length($buf). "\n"; print "bytes in is: $bytesin\n"; $buf = substr($buf,1,-2).chr(10); syswrite (MSGFILE, $buf, length($buf)); send ($new_sock, "got it, thanks. \n", 0); } close MSGFILE; close $sock;

Edited by planetscape - added readmore tags


In reply to long text message problem by codelady7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.