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)
In reply to Re: Sockets Help
by NetWallah
in thread Sockets Help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |