1
我想做一個perl程序,它允許用戶輸入主機和外部主機的端口號連接到使用IO ::套接字。它允許我運行該程序並輸入一個主機和一個端口,但它永遠不會連接,並說「無法連接到[主機]在c:\ users \ USER \ Documents \ code \ perl \ sql.pl行18,第2行「。我在做什麼錯了下面顯示的代碼?而且,我如何在我的主機上進行輸入驗證,可以是主機名或IP地址?謝謝一堆!以下代碼用戶輸入Perl與IO ::套接字
use IO::Socket
print "Host to connect to: ";
chomp ($host = <STDIN>);
print "Port to connect with: ";
chomp ($port = <STDIN>);
while(($port > 65535) || ($port <= 0)){
print "Port to connect with [Port > 0 < 65535] : ";
chomp ($port = <STDIN>);
}
print "\nConnecting to host $host on port $port\n";
$socket = new IO::Socket::INET (
LocalHost => '$host',
LocalPort => '$port',
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "Could not connect to $host";
很可能想從'$ host'和'$ port'刪除單引號:) :) – friedo 2010-05-06 21:19:46
謝謝,很好,我看着他們過去了...... – 2010-05-06 21:24:12