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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help using sockets in Perl

Status
Not open for further replies.

pdawlall

Programmer
Mar 6, 2003
5
ZA
Hi guys, can anyone help me. Im actually writing a script to distribute processing amoung 4 workstations.
The problem is that i have been having a problem sending and receiving data between sockets. For the time being im just trying it out on one workstation.
My server code is as follows:

#!/usr/bin/perl -w
use IO::Socket;
use Net::hostent;
foreach $argnum (0 .. $#ARGV) {
if ($ARGV[$argnum] eq "-s") {
$startframe = $ARGV[$argnum + 1];
}
if ($ARGV[$argnum] eq "-e") {
$endframe = $ARGV[$argnum + 1]; }

if ($ARGV[$argnum] eq "-proj") {
$projdir = $ARG[$argnum + 1] ; }

if ($ARGV[$argnum] eq "-rd") {
$renderdir = $ARG[$argnum + 1];
}
if ($ARGV[$argnum] = $#ARGV - 1){
$filename = $ARG[$argnum];
}

}

$PORT = 7700; # pick something not in use


$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1,
Type => SOCK_STREAM,
Family => AF_UNIX );
die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";


while ($client = $server->accept()) {
$client->autoflush(1);
print $client "Welcome to $0; Are you ready to Render \n";
$hostinfo = gethostbyaddr($client->peeraddr);
printf "\n[Connect from %s]\n", $hostinfo->name || $client->peerhost;

# $server->send($client, $startframe,18)
or die "Can't send: $!\n";
# THIS IS WHERE THE PROBLEM IS

printf "Sending Message $startframe";
# write ($client,$startframe,50);
# write ($client,$endframe,50);
close $client;
}

# My client code is as follows
#!/usr/bin/perl -w
use IO::Socket;
$remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "localhost",
PeerPort => "7700",
)
or die "cannot connect to port at localhost";

$remote->autoflush(1);

while ( <$remote> ) {
read ($remote,$buf,18);
printf $remote &quot;$buf \n&quot;;
# print

}

# print &quot;This is the startframe &quot;,$startframe;

kill(&quot;TERM&quot;,$remote);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top