perl6 IO::Socket::INET 无法从套接字接收数据:对等方重置连接 [英] perl6 IO::Socket::INET Could not receive data from socket: Connection reset by peer
本文介绍了perl6 IO::Socket::INET 无法从套接字接收数据:对等方重置连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例服务器:
#!/usr/bin/env perl6
my $listen = IO::Socket::INET.new(:listen, :localhost<localhost>, :localport(3333));
loop {
my $conn = $listen.accept;
while my $buf = $conn.recv(:bin) {
$conn.write: $buf;
}
$conn.close;
}
客户:
#!/use/bin/env perl6
my $c = IO::Socket::INET.new(:host<localhost>, :port(3333));
$c.print: "{time}\n";
#say $c.recv; #commented out on purpose
sleep 1 ;
$c.close ;
服务器错误:
无法从套接字接收数据:对等方重置连接在块<单元>中在 server4.p6 第 5 行
在每个块的服务器中,我尝试了 CATCH
和 QUIT
.我应该如何捕捉这个错误?
In the server on each of the blocks I tried CATCH
and QUIT
. How should I catch this error?
推荐答案
服务器需要捕获循环块中的错误:
Server needs to catch the error in the loop block:
#!/usr/bin/env perl6
my $listen = IO::Socket::INET.new(:listen, :localhost<localhost>, :localport(3333));
loop {
my $conn = $listen.accept;
while my $buf = $conn.get {
$conn.print: $buf;
}
$conn.close;
CATCH { default { say .^name, ': ', .Str , " handled in $?LINE";}}
}
服务器输出报告错误并保持运行以接受新连接:
Output of server reports the error and stays running to accept new connections:
perl6 --ll-exception server.p6
X::AdHoc: Could not receive data from socket: Connection reset by peer handled in 9
这篇关于perl6 IO::Socket::INET 无法从套接字接收数据:对等方重置连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文