<?xml version="1.0" encoding="windows-1252"?>
<node id="1006848" title="problem with reading from socket" created="2012-12-03 06:04:31" updated="2012-12-03 06:04:31">
<type id="115">
perlquestion</type>
<author id="992708">
MacScissor</author>
<data>
<field name="doctext">
Hello!

I have the following code:

&lt;code&gt;
#!/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-&gt;autoflush(1);
		my $request;
		print $request = &lt;CLIENT&gt;;
		#print $request;
		chomp $request;
		#chomp $request;

		if ($request =~ /^help/)
		{
			print CLIENT "help!\015\012";
		}
		elsif ($request =~ /^quit/)
		{
			last;
		}
	}
}
&lt;/code&gt;

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!</field>
</data>
</node>
