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
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