IO::Socket - i can't get it to read the data

2004-10-15 Thread Etienne Ledoux
greetings,

This program listens on a port for an incoming connection. Once someone 
connected it asks for a name and a password. but for some reason  I can't get 
it to read the name/password entered. what am i missing please...

while (($client,$client_address) = $server->accept()) {

# Get the client ip
($client_port, $c_ip) = sockaddr_in($client_address);
$clientip = inet_ntoa($c_ip);

print $client "\nname\n";
chomp ($cl_name = <$client>);
print $client "pass\n";
chomp ($cl_pass = <$client>);
print $client "\n$cl_name $cl_pass $clientip\n";

}

e.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: IO::Socket - i can't get it to read the data

2004-10-15 Thread Etienne Ledoux
ok it seems like the chomp it stuffin it up ?
if i removed it i get the correct data but with a \n



On Friday 15 October 2004 11:56, Etienne Ledoux wrote:
> greetings,
>
> This program listens on a port for an incoming connection. Once someone
> connected it asks for a name and a password. but for some reason  I can't
> get it to read the name/password entered. what am i missing please...
>
> while (($client,$client_address) = $server->accept()) {
>
> # Get the client ip
> ($client_port, $c_ip) = sockaddr_in($client_address);
> $clientip = inet_ntoa($c_ip);
>
> print $client "\nname\n";
> chomp ($cl_name = <$client>);
> print $client "pass\n";
> chomp ($cl_pass = <$client>);
> print $client "\n$cl_name $cl_pass $clientip\n";
>
> }
>
> e.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: IO::Socket - i can't get it to read the data

2004-10-15 Thread Etienne Ledoux
Would anybody have any idea why chomp is deleting the value ?

No matter how I try and do it. I even tried s/\n//,$value . afterwards I have 
a empty value. I don't understand what I'm doing wrong here and everywhere i 
check this it seems to be the right way to do it.  ?!?!

e.

On Friday 15 October 2004 12:16, Etienne Ledoux wrote:
> ok it seems like the chomp it stuffin it up ?
> if i removed it i get the correct data but with a \n
>
> On Friday 15 October 2004 11:56, Etienne Ledoux wrote:
> > greetings,
> >
> > This program listens on a port for an incoming connection. Once someone
> > connected it asks for a name and a password. but for some reason  I can't
> > get it to read the name/password entered. what am i missing please...
> >
> > while (($client,$client_address) = $server->accept()) {
> >
> > # Get the client ip
> > ($client_port, $c_ip) = sockaddr_in($client_address);
> > $clientip = inet_ntoa($c_ip);
> >
> > print $client "\nname\n";
> > chomp ($cl_name = <$client>);
> > print $client "pass\n";
> > chomp ($cl_pass = <$client>);
> > print $client "\n$cl_name $cl_pass $clientip\n";
> >
> > }
> >
> > e.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: IO::Socket - i can't get it to read the data

2004-10-15 Thread Jeff 'japhy' Pinyan
On Oct 15, Etienne Ledoux said:

>Would anybody have any idea why chomp is deleting the value ?
>
>No matter how I try and do it. I even tried s/\n//,$value . afterwards I have
>a empty value. I don't understand what I'm doing wrong here and everywhere i
>check this it seems to be the right way to do it.  ?!?!

The problem is that your data ends in \r\n, and the \r is a carriage
return.  If you print "jeff\rABC", you'd *see* "ABCf", because the \r
causes the cursor to go to the beginning of the line, thus overwriting
previous letters.  In your case, apparently the IP address is longer than
both the username and the password, so the IP is all you're seeing.

  ($user = <$client>) =~ s/\r?\n$//;
  ($pass = <$client>) =~ s/\r?\n$//;

That should work for you.

-- 
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: IO::Socket - i can't get it to read the data

2004-10-17 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Jeff 'japhy' Pinyan) writes:
>The problem is that your data ends in \r\n, and the \r is a carriage
>return.  If you print "jeff\rABC", you'd *see* "ABCf", because the \r
>causes the cursor to go to the beginning of the line, thus overwriting
>previous letters.  In your case, apparently the IP address is longer than
>both the username and the password, so the IP is all you're seeing.

And just so the original poster knows *why* they're getting a \r,
the reason is that the standard for line-oriented socket protocols
is to terminate lines with \r\n.  At least, what \r\n is on Unix-type
systems (\015\012); Perl changes the value of \n on some other platforms.
This is why Socket.pm exports upon request the symbol $CRLF, which is
the proper line terminator regardless.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]