in reply to Sockets Help
To make them usable, you would need to use either non-blocking reads, or threads.
Here is your code made more readable/idiomatic/perlish:
use strict; use IO::Socket; #use Win32::SerialPort; $|++; print "how many? "; my $PortCount= <STDIN>; chomp $PortCount; my (@sockinfo, $buffer); for (1..$PortCount){ my %sock; print "ip? "; $sock{IP} =<STDIN>; chomp($sock{IP}); print "port? "; $sock{PORT}=<STDIN>; chomp($sock{PORT}); push @sockinfo, \%sock; } foreach(@sockinfo){ ## print "Opening Socket to ",$_->{IP}," port ", $_->{PORT},"\n"; $_->{SOCKET}= IO::Socket::INET->new (PeerAddr=>$_->{IP}, PeerPort=>$_->{PORT}, Proto=>'tcp' +) or die "Can not connect: $@ \n IP=" . $_->{IP} . " Port=" . $_->{PORT}; $_->{SOCKET}->recv($buffer,1024); print $buffer; }
Earth first! (We'll rob the other planets later)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sockets Help
by Anonymous Monk on Aug 25, 2004 at 02:47 UTC |