Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginner's question about socket programming

Status
Not open for further replies.

orangegal

Technical User
Oct 12, 2005
15
US
dear all, how do i send an array of items, for example a file or some variables, using perl?? i found the following sample code online, but it only send a message over

thanks alot

===================================
#!/usr/bin/perl -w

use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => '119.0.0.1', #IP of node to connect to
PeerPort => '9999', #Port on server to connect to
Proto => 'tcp', #Protocol to use for connection
);
die "Could not create socket: $!\n" unless $sock;
#Error message if client socket can't be opened
print $sock "Hello there!\n"; #write to stdout
close($sock);
 
Instead of "hello there!", your message could be the contents of a file read in and printed to the socket.

An array might mean having to set a context
print $sock "MODE=ARRAY\n";
print $sock join "###", @array. "\n";
print $sock "ARRAYEND\n"

Gotta run
HTH
--Paul

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
thank you paul!
but if i want to send 5 messages over, what do i do?
how about 20 variables and their values??
 
how can i just send the variables over without printing it?? for instance, i just send those variables for the other program to use on the server side. just alittle confused
 
Data::Dumper will do what you need.

Give it a data structure, shove what it gives you back through the socket, eval it at the far end.

Make sure you only eval stuff you're sure about though obviously :)

Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
print=== write to socket, the client determines eligibility of data

Send what you want, just make sure the client expects it

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top