vortmax has asked for the wisdom of the Perl Monks concerning the following question:
client#!/usr/bin/perl -w use strict; use IO::Socket; my $socket = IO::Socket::INET->new('LocalPort' => 7890, 'Proto' => 'tcp', 'Listen' => SOMAXCONN) or die "Can't create socket ($!)\n"; print "[Server Started]\n"; while (my $client = $socket->accept) { if ($client->peeraddr) { print "[Connect from " . gethostbyadd +r($client->peeraddr, AF_INET) . "]\n"; } my $reply = "test"; my $act = <$client>; print $act; print $client "$reply\n"; close $client or die "Can't close ($!)\n"; } die "Can't accept socket ($!)\n";
I haven't written the meat of the code to perform the SNMP actions, but they will just be subs in a module used in the server program. This works okay for passing pings and pongs back and forth, but I am looking to pass more data. Is there a way I can pass an array or a hash across the socket without formatting it to ASCII first then having to reassemble on the other end? If not, I might just use the SSH module instead and save having to code a server.#!/usr/bin/perl -w use strict; use IO::Socket; my $host = shift || die "No host"; my $port = 7890; my $action = shift || die "No action"; my $ip = shift || die "No ip"; my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp') or die "Can't Bind :$@!\n\n"; print $sock "$action "; print $sock "$ip\n"; while( <$sock> ) { print $_; } close $sock;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket... passing more then just text
by Fletch (Bishop) on Jun 19, 2008 at 12:10 UTC | |
|
Re: IO::Socket... passing more then just text
by pc88mxer (Vicar) on Jun 19, 2008 at 12:12 UTC | |
|
Re: IO::Socket... passing more then just text
by zentara (Cardinal) on Jun 19, 2008 at 13:24 UTC |