小编Car*_*ovo的帖子

保持打开套接字连接Perl

我创建了一个Perl脚本,在我的服务器上打开一个新的套接字.当我用telnet连接到套接字并且我写(并接收)某些东西时,连接关闭.

#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use IO::Socket::INET;
$| = 1;
my $sock = IO::Socket::INET->new(Listen    => 5,
                                 LocalAddr => 'localhost',
                                 LocalPort => 9000,
                                 Reuse => 1,
                                 Proto     => 'tcp');
die "Socket not created $!\n" unless $sock;
print "Server waiting for connections\n";
while(1)
{
    # waiting for a new client connection
    my $client_socket = $sock->accept();

    # get information about a newly connected client
    my $client_address = $client_socket->peerhost();
    my $client_port = $client_socket->peerport();
    print "Connection from $client_address:$client_port\n";

    # read up to …
Run Code Online (Sandbox Code Playgroud)

sockets perl network-programming

3
推荐指数
1
解决办法
239
查看次数

标签 统计

network-programming ×1

perl ×1

sockets ×1