[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Clipboard Transfer via AppleTalk



This uses the Clipboard.XFCN from online and on the MacPerl CD-ROM.  One
machine runs the server, the other a client that either sends the clipboard
to the other machine, or retrieves it.

#!perl -w
# clipboard_server.plx

package Dartmouth;
MacPerl::LoadExternals("Clipboard.XFCN");

package main;
use strict;
use IO::Socket;
my($answer, $client, $server);

$server = IO::Socket::APPLETALK->new(
  Object  => 'ClipboardServer1',
  Listen  => 1,
) or die('Cannot start server');

while ($client = $server->accept()) {
  my $do = <$client>;
  my @data;
  while (<$client>) {
    last if /^END\n$/;
    push @data, $_;
  }
  if ($do =~ /^Get/) {
    print $client "Sending:\n", Dartmouth::Clipboard();
  } else {
    Dartmouth::Clipboard(join('', @data));
    print $client "Saving:\n", @data;
  }
  close($client);
  # exit;  # always run server?
}

__END__


#!perl -w
# clipboard_client.plx

package Dartmouth;
MacPerl::LoadExternals('Clipboard.XFCN');

package main;
use strict;
use IO::Socket;
my($sock, $ask);

$ask = MacPerl::Answer('Send or Fetch Clipboard?', 'Send', 'Fetch', 'Cancel');
exit unless $ask;

$sock = IO::Socket::APPLETALK->new(
  Object => 'ClipboardServer1'
) or die('Cannot start client');

if ($ask == 1) {
  print $sock join("\n", "Get", "END"), "\n";
  my $reply = <$sock>;
  die "Bad reply: $reply" unless $reply eq "Sending:\n";
  Dartmouth::Clipboard(join('', <$sock>));
} elsif ($ask == 2) {
  print $sock join("\n", "Put", Dartmouth::Clipboard(), "END"), "\n";
  my $reply = <$sock>;
  die "Bad reply: $reply" unless $reply eq "Saving:\n";
}

__END__


--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch