From bott at grpl.org Fri Sep 30 09:52:37 2005 From: bott at grpl.org (Bill Ott) Date: Fri, 30 Sep 2005 12:52:37 -0400 Subject: [grand-rapids-pm-list] The Perl - TCP/IP serial cable Message-ID: <433D6D55.90804@grpl.org> I had a request for another look at the code for the serial cable. Here are the two pieces. -Bill com2sock.pl: #!/usr/bin/perl #use strict; use IO::Socket; use Device::SerialPort; $com2 = Device::SerialPort->start ("/usr/local/work/cuaa0.cfg") or die "Can't start COM1\n"; my ($remote, $port, $iaddr, $paddr, $proto, $line, $buf); $remote = '123.123.123.123'; $port = 12; # random port $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); $data = ''; while(1) { if ($data = $com2->input) { socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "no connecty...\n"; $buf = $data; print SOCK $data; close SOCK; $data = "0"; } } sock2com.pl: #!/usr/bin/perl #use strict; use IO::Socket; use Device::SerialPort; $com2 = Device::SerialPort->start ("/usr/local/work/cuaa0.cfg") or die "Can't start COM1\n"; $sock = new IO::Socket::INET (LocalHost => '123.123.123.123', LocalPort => 10, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "No Socket because: $! \n" unless $sock; while ($new_sock = $sock->accept()) { while (defined ($buf = <$new_sock>)) { #print "$buf\n"; $com2->write($buf); print $new_sock "Thanx\n"; } } close ($sock); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/grand-rapids-pm-list/attachments/20050930/d239ab77/attachment.html From mheusser at charter.net Fri Sep 30 11:40:20 2005 From: mheusser at charter.net (Matthew Heusser) Date: Fri, 30 Sep 2005 14:40:20 -0400 Subject: [grand-rapids-pm-list] The Perl - TCP/IP serial cable Message-ID: <4ck04t$1gmvrlg@mxip12a.cluster1.charter.net> I'm terribly sorry I had to miss the presentation. Is there any chance we could get all the code up on grand-rapids.pm.org soon? thanks! --heusser > > From: Bill Ott > Date: 2005/09/30 Fri PM 12:52:37 EDT > To: grand-rapids-pm-list at pm.org > Subject: [grand-rapids-pm-list] The Perl - TCP/IP serial cable > > I had a request for another look at the code for the serial cable. Here > are the two pieces. > > -Bill > > > com2sock.pl: > > #!/usr/bin/perl > #use strict; > use IO::Socket; > use Device::SerialPort; > > $com2 = Device::SerialPort->start ("/usr/local/work/cuaa0.cfg") or die "Can't start COM1\n"; > my ($remote, $port, $iaddr, $paddr, $proto, $line, $buf); > $remote = '123.123.123.123'; > $port = 12; # random port > $iaddr = inet_aton($remote) || die "no host: $remote"; > $paddr = sockaddr_in($port, $iaddr); > $proto = getprotobyname('tcp'); > $data = ''; > > while(1) { > if ($data = $com2->input) { > socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; > connect(SOCK, $paddr) || die "no connecty...\n"; > $buf = $data; > print SOCK $data; > close SOCK; > $data = "0"; > } > } > > > sock2com.pl: > > #!/usr/bin/perl > #use strict; > use IO::Socket; > use Device::SerialPort; > > $com2 = Device::SerialPort->start ("/usr/local/work/cuaa0.cfg") or die "Can't start COM1\n"; > $sock = new IO::Socket::INET (LocalHost => '123.123.123.123', > LocalPort => 10, > Proto => 'tcp', > Listen => 5, > Reuse => 1 ); > die "No Socket because: $! \n" unless $sock; > > while ($new_sock = $sock->accept()) { > while (defined ($buf = <$new_sock>)) { > #print "$buf\n"; > $com2->write($buf); > print $new_sock "Thanx\n"; > > } > } > close ($sock); > > > > -------------- next part -------------- _______________________________________________ grand-rapids-pm-list mailing list grand-rapids-pm-list at pm.org http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list