perl 本机调试,提示connect() 拒绝连接
各位好,现在学习perl编程,在本机调试的时候,出现connect() 拒绝连接,应该怎么处理呀?
如果是后面跟一个网址的话,就会提示:
connect() failed:连接超时 at ./tcp.pl line 14.
#! /usr/bin/perluse strict;use warnings;use Socket;use IO::Handle;my ($bytes_out,$bytes_in) = (0,0);my $host = shift() || 'localhost';my $port = shift() || getservbyname('echo','tcp');my $protocol = getprotobyname('tcp');$host = inet_aton($host) or die "$host:unknow host.";socket(SOCK,AF_INET,SOCK_STREAM,$protocol) or die "socket() failed:$!";my $dest_addr = sockaddr_in($port,$host);connect(SOCK,$dest_addr) or die "connect() failed:$!";SOCK->autoflush(1);while(my $msg_out = <>){ print SOCK $msg_out; my $msg_in = <SOCK>; print SOCK $msg_in; $bytes_out += length($msg_out); $bytes_in += length($msg_in);}close SOCK;print STDERR "bytes_send = $bytes_out,bytes_received = $bytes_in\n";