Hi,
I've just started looking at Sockets as a method of getting data from one server to another.
My setup is relatively simple having a client and server system. The client sends commands to the server over TCP and ideally should receive multiple lines worth of data back for processing. The problem I have is that I get client 'hangs' which prevents the application from exiting when I ask for, then receive information from the server: (some data is sent back OK)
Client Application: (relevent code shown only)
note: if I know how much information is returned from the server then I can retrieve as follows:
unfortunately however the information returned is not fixed.
Server Application: (relevent code only)
I'd really appreciate any hints you can provide on how to resolve...
Steven
I've just started looking at Sockets as a method of getting data from one server to another.
My setup is relatively simple having a client and server system. The client sends commands to the server over TCP and ideally should receive multiple lines worth of data back for processing. The problem I have is that I get client 'hangs' which prevents the application from exiting when I ask for, then receive information from the server: (some data is sent back OK)
Client Application: (relevent code shown only)
Code:
$sock->autoflush(1);
print $sock "COMMAND\n"; # send command to server
# print output from server to client application
# end application will store to array
while (<$sock>)
{
print scalar <$sock>;
}
close ($sock);
note: if I know how much information is returned from the server then I can retrieve as follows:
Code:
print scalar <$sock>;
print scalar <$sock>;
...
print scalar <$sock>;
unfortunately however the information returned is not fixed.
Server Application: (relevent code only)
Code:
STDOUT->autoflush(1);
my($new_sock, $buf);
while ( $new_sock = $sock->accept() )
{
while (defined($buf = <$sock_handle>))
{
# respond to client:
foreach ($buf)
{
/^COMMAND$/ and
# e.g. return name of all text files back to server
opendir (PATH,$path);
foreach my $entry ( readdir PATH )
{
if ($entry =~ /\.txt/i)
{
print $sock_handle $entry,"\n";
}
}
closedir (PATH);
last;
}
}
close ($sock_handle);
}
I'd really appreciate any hints you can provide on how to resolve...
Steven