Professional Web Applications Themes

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

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

  1. #1

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

    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.
    Etienne Guest

  2. #2

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

    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: 
    Etienne Guest

  3. #3

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

    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. mmmm ?!?!

    e.

    On Friday 15 October 2004 12:16, Etienne Ledoux wrote: [/ref]
    Etienne Guest

  4. #4

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

    On Oct 15, Etienne Ledoux said:
     

    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

    Jeff Guest

Similar Threads

  1. Read From Socket
    By Roman in forum PERL Beginners
    Replies: 2
    Last Post: May 6th, 10:56 AM
  2. Can' t read all bytes from Socket
    By James Kipp in forum PERL Beginners
    Replies: 17
    Last Post: December 2nd, 01:18 PM
  3. Socket not blocking on read()
    By Charlie in forum UNIX Programming
    Replies: 5
    Last Post: September 19th, 03:29 PM
  4. socket read when io happens
    By Paras in forum UNIX Programming
    Replies: 3
    Last Post: August 12th, 06:27 AM
  5. EAGAIN during socket read
    By turtle in forum Sun Solaris
    Replies: 3
    Last Post: July 16th, 07:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139