# 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |