#!/usr/local/bin/perl -w # modules required use strict; use IO::Socket; use IO::Tee; use Fcntl; # get port number and server IP my $SERVICE = <DATA>; my $REMOTE = <DATA>; # connection to remote server (data source) my $remote = new IO::Socket::INET( PeerPort => $SERVICE, PeerAddr => $REMOTE, Proto => 'tcp', Type => SOCK_STREAM, ) or die "Can't connect: $!\n"; # local port to accept connections from probes my $local = new IO::Socket::INET( LocalPort => $SERVICE, Proto => 'tcp', Listen => 3, Reuse => 1, ) or die "Can't create server : $!\n"; # make local ports non-blocking fcntl($local,F_SETFL, fcntl($local,F_GETFL,0) | O_NONBLOCK); # build a hash for client connections # use a STDOUT so I can see what's happening on server locally. # can drop for production my %clients = ("StdOut"=>\*STDOUT,); my $buf; # loop forever while (1) { # if a probe connects add details to hash my $client = $local->accept(); $clients{$client} = $client if $client; # this bit remove clients that have disconnected foreach (keys %clients) { delete $clients{$_} if ($_ ne "StdOut" and !$clients{$_}-> +connected()); } # send data to all connected clients my $tee = IO::Tee->new(values %clients); print $tee $buf if (defined $remote and $buf = <$remote>); } __END__ 8099 <server ip goes here>
In reply to Re^2: Port duplicator
by tweetiepooh
in thread Port duplicator
by tweetiepooh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |