|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: |
#!/usr/bin/perl
use strict;
use warnings;
use IO::Async::Loop;
use IO::Async::Stream;
our $LOGLEVEL = 4; # 1-Error, 2-Warn, 3-info, 4-debug, 5-silly
my $LISTEN_PORT = 3389;
my $CONNECT_HOST = "10.0.0.64"; #- to be replaced
my $CONNECT_PORT = 1080; #- to be replaced
my %stream1 = ();
my %stream2 = ();
my %connect_port = ();
my %connect_host = ();
my $loop = IO::Async::Loop->new;
$loop->listen
(
service => $LISTEN_PORT,
socktype => 'stream',
on_accept => sub
{
my ( $socket1 ) = @_;
# $socket is just an IO::Socket reference
my $p = $socket1->peerhost . ":" . $socket1->peerport;
wlog(3,"New connection from $p");
##############################################
$stream1{$p} = IO::Async::Stream->new
(
handle => $socket1,
on_read => sub
{
my ( $self, $buffref, $closed ) = @_;
if( $$buffref =~ /RPC2/ )
{
wlog (3,"XMLRPC detected");
($connect_host{$p},$connect_port{$p}) = xmlrpc($$buffref);
wlog(4,"host:" . $connect_host{$p} . " port:" . $connect_port{$p});
}
# Just copy all the data
if (defined $stream2{$p})
{
$stream2{$p}->write( $$buffref ); $$buffref = "";
}
return 0;
},
on_closed => sub
{
$stream2{$p}->close_when_empty;
delete $stream2{$p};
wlog(3,"Connection from $p closed");
},
);
$loop->add( $stream1{$p} );
##############################################
wlog(4,"MARK: if defined connect_host");
if ( defined $connect_host{$p} )
{
wlog(4,"MARK: Start of loop->connect");
wlog(4,"connect_host set to". $connect_host{$p}) if defined $connect_host{$p};
$loop->connect(
host => $CONNECT_HOST, #should be $connect_host{$p}
service => $CONNECT_PORT, #should be $connect_port{$p}
on_connected => sub
{
my ( $socket2 ) = @_;
$stream2{$p} = IO::Async::Stream->new
(
handle => $socket2,
on_read => sub
{
my ( $self, $buffref, $closed ) = @_;
# Just copy all the data
$stream1{$p}->write( $$buffref ); $$buffref = "";
return 0;
},
on_closed => sub
{
$stream1{$p}->close_when_empty;
wlog(3,"Connection to $CONNECT_HOST:$CONNECT_PORT closed");
},
);
#$loop->add( $stream1{$p} );
$loop->add( $stream2{$p} );
},
on_resolve_error => sub { wlog(1,"Cannot resolve - $_[0]"); },
on_connect_error => sub { wlog(1,"Cannot connect"); },
);
}
#############################################
},
on_resolve_error => sub { wlog(1,"Cannot resolve - $_[0]"); die;},
on_listen_error => sub { wlog(1,"Cannot listen"); die; },
);
$loop->loop_forever;
sub wlog
{
my ($level,$msg) = @_;
if ($LOGLEVEL >= $level)
{
#for now print to sderror.
print STDERR $msg . "\n";
}
}
sub xmlrpc
{
my $input = @_;
#magic goes here
return ("10.0.0.64", 1080);
}
|
Advertisement
| Hall of Fame |
There are currently no qualifying experts in CGI
There are currently no qualifying experts in CGI