[grand-rapids-pm-list] The Perl - TCP/IP serial cable
Matthew Heusser
mheusser at charter.net
Fri Sep 30 11:40:20 PDT 2005
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 <bott at grpl.org>
> 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
More information about the grand-rapids-pm-list
mailing list