Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl Sock服务器和客户端_Perl_Socks - Fatal编程技术网

Perl Sock服务器和客户端

Perl Sock服务器和客户端,perl,socks,Perl,Socks,我有下面的Socks服务器 my $socks_server = IO::Socket::Socks->new( ProxyAddr => "localhost", ProxyPort => 8000, Listen => 1, ) or die "socket error"; while(1) { my $client = $socks_server->accept(); pri

我有下面的Socks服务器

my $socks_server = IO::Socket::Socks->new(
  ProxyAddr   => "localhost",
  ProxyPort   => 8000,
  Listen      => 1,
  ) or die "socket error";
 
while(1) {
  my $client = $socks_server->accept();
  print $client;
  unless ($client) {
    print "ERROR:";
    next;
  }
}
 
和下面的Socks客户端

use strict;
use warnings;
use IO::Socket::Socks;
 
my $socks_client = IO::Socket::Socks->new(
  ProxyAddr   => "localhost",
  ProxyPort   => "8000",
) or die $SOCKS_ERROR;
 
print $socks_client "foo\n";
$socks_client->close();

Socks客户端打印“foo\n”,如何让Socks服务器在收到它时将其打印到控制台?

以下代码仅用于演示,为简单起见,已关闭身份验证

该代码基于以下文档:

服务器.pl的代码

use strict;
use warnings;
use feature 'say';

use IO::Socket::Socks ':constants';

my $SOCKS_ERROR = 'Error: SOCKS';
 
my $socks_server = IO::Socket::Socks->new(
  ProxyAddr   => "localhost",
  ProxyPort   => 8000,
  Listen      => 1,
  UserAuth    => \&auth,
  RequireAuth => 0
) or die $SOCKS_ERROR;
 
while(1) {
  my $client = $socks_server->accept();
   
  unless ($client) {
    print "ERROR: $SOCKS_ERROR\n";
    next;
  }
 
  my $command = $client->command();
  if ($command->[0] == CMD_CONNECT) {
     # Handle the CONNECT
     $client->command_reply(REPLY_SUCCESS, 'localhost', 8000);
  }
   
  print while <$client>;
   
  $client->close();
}
 
sub auth {
  my ($user, $pass) = @_;
   
  return 1 if $user eq "foo" && $pass eq "bar";
  return 0;
}
use strict;
use warnings;
use feature 'say';

use IO::Socket::Socks;
 
my $socks_client = IO::Socket::Socks->new(
  ProxyAddr   => "localhost",
  ProxyPort   => "8000",
  ConnectAddr => "localhost",
  ConnectPort => "8022",
) or die $SOCKS_ERROR;
 
print $socks_client $_ for <DATA>;

$socks_client->close();

__DATA__
-----------------------------------------------
This a test message sent from remote client for
SOCKS demonstration code.

Enjoy your day.
客户端pl上的输出

C:\....\examples\socks_server.pl
-----------------------------------------------
This a test message sent from remote client for
SOCKS demonstration code.

Enjoy your day.
C:\...\examples\socks_client.pl
C:\...>

accept
函数返回一个套接字对象,而不是您发送的字符串。读取模块的。如何读取我发送的字符串?
send
recv
?当
RequireAuth
设置为0时,设置
UserAuth=>&auth
pointless@Dada--可以随意将其设置为
1
,并实现身份验证机制。