MacScissor has asked for the wisdom of the Perl Monks concerning the following question:
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!#!/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; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem with reading from socket
by rjt (Curate) on Dec 03, 2012 at 11:56 UTC |