B
Brad
I have been working on this for a few days now, and still feel stuck.
I have a large HASH which I need to send via TCP to a server. I need
to use IO::Socket::INET for the TCP connection. While there is
probably a _better_ way, I have been playing around with Data:umper
convert the HASH, then rebuild it on the other end. The problem is I
cannot seem to rebuild the data.
Code:
Client (sending HASH)
---------------------
use Data:umper;
use IO::Socket::INET;
$TEST{'test'}{'test1'} = 1;
$TEST{'test2'}{'test3'} = 2;
$socket = IO::Socket::INET->new(PeerAddr => localhost,
PeerPort => 2002,
Proto => "tcp",
Type => SOCK_STREAM)
or die "Couldn't connect to $remote_host:$remote_port : $!\n";
$Data:umper:air = " : "; # specify hash key/value
separator
$Data:umper::Indent = 0;
# send something over the socket,
print $socket Dumper(\%TEST);
# and terminate the connection when we're done.
close($socket);
---------------------
Server
---------------------
use Data:umper;
use IO::Socket::INET;
$server = IO::Socket::INET->new(LocalPort => 2002,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10 ) # or SOMAXCONN
or die "Couldn't be a tcp server on port $server_port: $!\n";
while ($client = $server->accept()) {
$data = <$client>;
#print "$data\n";
#$Data:umper:air = " : "; # specify hash key/value
separator
#$Data:umper::Indent = 0;
#eval $data;
print Dumper $data;
}
close($server);
---------------------
I have tried other methods of re-building the hash on the server-end.
The answer is probably right in front of me, but I just don't see it
on the module's page (
http://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm ) or in the
perldoc.
Any help, or any ideas for a better solution, is appreciated.
Thanks,
Brad
I have a large HASH which I need to send via TCP to a server. I need
to use IO::Socket::INET for the TCP connection. While there is
probably a _better_ way, I have been playing around with Data:umper
convert the HASH, then rebuild it on the other end. The problem is I
cannot seem to rebuild the data.
Code:
Client (sending HASH)
---------------------
use Data:umper;
use IO::Socket::INET;
$TEST{'test'}{'test1'} = 1;
$TEST{'test2'}{'test3'} = 2;
$socket = IO::Socket::INET->new(PeerAddr => localhost,
PeerPort => 2002,
Proto => "tcp",
Type => SOCK_STREAM)
or die "Couldn't connect to $remote_host:$remote_port : $!\n";
$Data:umper:air = " : "; # specify hash key/value
separator
$Data:umper::Indent = 0;
# send something over the socket,
print $socket Dumper(\%TEST);
# and terminate the connection when we're done.
close($socket);
---------------------
Server
---------------------
use Data:umper;
use IO::Socket::INET;
$server = IO::Socket::INET->new(LocalPort => 2002,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10 ) # or SOMAXCONN
or die "Couldn't be a tcp server on port $server_port: $!\n";
while ($client = $server->accept()) {
$data = <$client>;
#print "$data\n";
#$Data:umper:air = " : "; # specify hash key/value
separator
#$Data:umper::Indent = 0;
#eval $data;
print Dumper $data;
}
close($server);
---------------------
I have tried other methods of re-building the hash on the server-end.
The answer is probably right in front of me, but I just don't see it
on the module's page (
http://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm ) or in the
perldoc.
Any help, or any ideas for a better solution, is appreciated.
Thanks,
Brad