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

IO::SOCKET and AutoFlush - not working

Status
Not open for further replies.

SteveJR

Programmer
Aug 13, 2001
72
GB
Hi,

Noobie Perl programmer here so please go easy on me!

I am trying to create a simple Perl Server that uses IO::Socket. I want it to take a message from the client, check if the message contains a piece of text, do something and then reply. I do not want the client connection closed after the reply though.

So, I have been searching the net for the past couple of days, been doing lots of reading on Perl Clients & Servers, looking at lots of examples and decided to use the the below which is written by Peter Lewis:


I have amended it slightly:

- removed the while loop in sub HandleClient and
instead have an if statement to check for some text:
if ( $line =~ /SECURITY/ ) {
my $resp_line = "0810";
my $resp_len = length($resp_line);
SendMessage( $resp_len.$resp_line );
}
- added $client->autoflush(1); in sub HandleServer
- added $server->autoflush(1); in sub OpenServer

So, the problem is that I don't see any messages back on my client. Again, I have searched on the net and read up about setting autoflush to 1, trying the $|=1 but to no avail. The server seems to buffer the output back to the client until, I am guessing, it hits a default buffer size and flushes then.

I am running both the client and server on windows. The client is a standalone test tool where I define a destination address and port. Everything connects ok, I see the message leaving the client, reaching the server and the server trying to respond.

Can anyone please help?

Many thanks,

Steve
 
Solved - client was expecting a length at the beginning of the response message so that it could calculate the buffer size it was to receive.

Note to self - RTFM :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top