本文介绍了使用IO :: Socket :: IP ???如何在Perl Ipv6中建立客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找到一个简单的客户端ipv6脚本当然可以使用Evens服务器脚本不知道我在做什么,所以我所能做的就是重写某人直到我知道我在做什么...之前其他人都在工作...

I have been trying to find a simple client ipv6 script that would work with Evens server script , of course I dont know what Im doing, so all I can do is rewrite someone else's work until I know what Im doing ...

这是可在Microsoft寡妇服务器上工作的服务器脚本

so here is a server script that works on Microsoft widows server

   use IO::Socket::IP -register; 
   my $sock = IO::Socket->new(
   Domain    => PF_INET6,
   LocalHost => "::1",
   Listen    => 1,
   ) or die "Cannot create socket - $@\n";

   print "Created a socket of type " . ref($sock) . "\n";

   {
   $in = <STDIN>;
   print $in->$sock;
   redo }

当然$ in-> $ sock不起作用,因为我不知道如何发送仅使用$ sock的数据?所以我需要知道如何正确发送信息,
我需要的是一个客户端脚本以连接到上述脚本使用ipv6协议

of course the $in->$sock is not working, cause I dont know how to send data using just $sock ???so I need to know how to send information properly and
what I need is A client script to connect to the above scriptusing the ipv6 protocol

任何人都可以帮忙吗???我希望能够从一个发送信息使用此功能将perl程序转换为另一个perl程序能够来回发送信息会理想...

can anyone help with this ???I would like to be able to send information from one perl program to another perl program using this being able to send information back and forth would be Ideal ...

先谢谢了-马克

推荐答案

这是服务器套接字(Listen => 1),因此必须accept连接.

That's a server socket (Listen => 1), so you have to accept a connection.

use IO::Socket::IP -register;

my $listen_sock = IO::Socket::IP->new(
   LocalHost => "::1",                    # bind()
   Listen    => 1,                        # listen()
) or die "Cannot create socket - $@\n";

print("Listening to ".$listen_sock->sockhost()." "
                     .$listen_sock->sockport()."\n");

while (1) {
   my $sock = $listen_sock->accept()
      or die $!;

   print("Connection received from ".$sock->peerhost()." "
                                    .$sock->peerport()."\n");

   while (<$sock>) {
      print $sock "echo: $_";
   }
}

客户:

use IO::Socket::IP -register;

@ARGV == 2 or die("usage");
my ($host, $port) = @ARGV;

my $sock = IO::Socket::IP->new(
   PeerHost => $host,                     # \ bind()
   PeerPort => $port,                     # /
) or die "Cannot create socket - $@\n";

print $sock "Hello, world!\n";
$sock->shutdown(1);                       # Done writing.
print while <$sock>;

注释指示用于执行操作的基础系统调用.

The comments indicate the underlying system call used to perform the action.

这篇关于使用IO :: Socket :: IP ???如何在Perl Ipv6中建立客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:22