For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2005 > How to send struct data over socket?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to send struct data over socket?
poohc1234@yahoo.com

2005-06-09, 8:57 pm

Hi Perl Experts,
I am trying to send a data structure over the IO::Socket, but I think I
may have simplied things and I don't know how to work it out.

server.pl side I print the struct data:

print $sock "$SocketData\n";

hoping that the client would pick up.
Well, I don't know how to handle the incoming ARRAY(0x224fb4) so I can
retrieve the data fields of the struct.

Please advise.
Thanks,
Jiac

Ruey-Cheng Chen

2005-06-09, 8:57 pm

Actually your code would send out a reference of ARRAY, which is
definitely not what you're been expected. All you have to do is to
'stringify' your data on one end and reform it on the other end.

See if this module, Data::Serializer, could do any help.

Jim Gibson

2005-06-09, 8:57 pm

In article <1118342462.233631.106040@g49g2000cwa.googlegroups.com>,
<poohc1234@yahoo.com> wrote:

> Hi Perl Experts,
> I am trying to send a data structure over the IO::Socket, but I think I
> may have simplied things and I don't know how to work it out.
>
> server.pl side I print the struct data:
>
> print $sock "$SocketData\n";
>
> hoping that the client would pick up.
> Well, I don't know how to handle the incoming ARRAY(0x224fb4) so I can
> retrieve the data fields of the struct.


Putting an array reference in double quotes yields just what you see:
"ARRAY(<hex address> )". You need to stringify the array data in a way
that the array can be reconstructed, send the string, then use it to
reconstruct the array.

The modules Storable and Data::Dumper, both part of the basic Perl
distribution, allow you to do this. See the documentation for those
modules:

perldoc Storable
perldoc Data::Dumper

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
dw

2005-06-10, 3:59 am

> server.pl side I print the struct data:
>
> print $sock "$SocketData\n";
>

You may also want to consider YAML serialisation, ie:

use YAML;
.....
print $sock YAML::Dump($SocketData);

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com