Hello!
I have the following code:
#!/usr/bin/perl
use strict;
use warnings;
use Socket;
use FileHandle;
my $request;
my $port = 6699;
my $proto = getprotobyname('tcp');
socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsockopt:
+ $!\n";
my $socketaddress = sockaddr_in($port, INADDR_ANY);
bind(SERVER, $socketaddress) or die "bind: $!\n";
listen(SERVER, SOMAXCONN) or die "listen: $!\n";
print "starting on port: $port...\n";
my $client;
for (; $client = accept(CLIENT, SERVER); close CLIENT)
{
print CLIENT "ready\015\012";
while (1)
{
CLIENT->autoflush(1);
my $request;
print $request = <CLIENT>;
#print $request;
chomp $request;
#chomp $request;
if ($request =~ /^help/)
{
print CLIENT "help!\015\012";
}
elsif ($request =~ /^quit/)
{
last;
}
}
}
This script is executed under Windows. I connect to the socket via telnet with putty. The first line that I send via telnet is received by the server, but I have strange chars before the received command. For example, when i type "help", the server receives the following: http://i.imgur.com/J0RVu.jpg
Thanks in advance!