socket connection with perl
Wednesday, June 16, 2010 10:45:26 AM
#!/usr/bin/perl
use IO::Socket;
$remote_host="www.ap.ntdtv.com";
$remote_port="80";
#$socket = IO::Socket::INET->new("$remote_host:$remote_port");
#print "$socket\n";
#or die "Can't connect!!: $!\n"
;
$socket = IO::Socket::INET->new(
Proto => "tcp",
Timeout => 5, # in seconds
PeerAddr => $remote_host,
PeerPort => $remote_port,
Type => SOCK_STREAM,
)
#or die $@
;
if($socket) {$success=1};
if(!$socket) {$success=0};
if($success eq 1){print "socket connected!!\n"};
if($success eq 0){print "socket無法建立!!\n"};
# print $socket
#print $socket "data\n";
#$line=<$socket>;
#print $line;
# terminate the connection
close($socket);
use IO::Socket;
$remote_host="www.ap.ntdtv.com";
$remote_port="80";
#$socket = IO::Socket::INET->new("$remote_host:$remote_port");
#print "$socket\n";
#or die "Can't connect!!: $!\n"
;
$socket = IO::Socket::INET->new(
Proto => "tcp",
Timeout => 5, # in seconds
PeerAddr => $remote_host,
PeerPort => $remote_port,
Type => SOCK_STREAM,
)
#or die $@
;
if($socket) {$success=1};
if(!$socket) {$success=0};
if($success eq 1){print "socket connected!!\n"};
if($success eq 0){print "socket無法建立!!\n"};
# print $socket
#print $socket "data\n";
#$line=<$socket>;
#print $line;
# terminate the connection
close($socket);






