Carriage Returns and sockets

Discussion in 'Perl' started by Iceberg, Sep 6, 2003.

  1. Iceberg

    Iceberg Guest

    Hi, I'm using ActivePerl on Win98 and this is starting to annoy me.
    Why isn't \n accepted as a carriage return when I'm using sockets?
    If I run the following program, I get no response other than the SMTP info
    header. Using a proxy to investigate, I found that what is getting sent to
    the server is only an 0a character not an 0d0a sequence, any help on this
    would be great appreciated. I've already tried sending \r\n and that makes
    no difference.

    #!/usr/bin/perl -w
    use IO::Socket;
    $remote = IO::Socket::INET->new(
    Proto => "tcp",
    PeerAddr => "smtp_host",
    PeerPort => "25",
    )
    or die "cannot connect to server";
    # get SMTP server welcome
    $line=<$remote>;
    print "$line\n";

    # send HELO
    print $remote "HELO\n"; # the \n here doesn't seem to work

    # get reply
    $line=<$remote>;
    print "$line\n";
     
    Iceberg, Sep 6, 2003
    #1
    1. Advertising

  2. Iceberg

    Iceberg Guest

    Just found out the solution:
    $EOL = "\015\012";
    print $remote "HELO".$EOL;

    but does anybody know any easier way?

    "Iceberg" <> wrote in message
    news:T8o6b.2420$...
    > Hi, I'm using ActivePerl on Win98 and this is starting to annoy me.
    > Why isn't \n accepted as a carriage return when I'm using sockets?
    > If I run the following program, I get no response other than the SMTP info
    > header. Using a proxy to investigate, I found that what is getting sent to
    > the server is only an 0a character not an 0d0a sequence, any help on this
    > would be great appreciated. I've already tried sending \r\n and that makes
    > no difference.
    >
    > #!/usr/bin/perl -w
    > use IO::Socket;
    > $remote = IO::Socket::INET->new(
    > Proto => "tcp",
    > PeerAddr => "smtp_host",
    > PeerPort => "25",
    > )
    > or die "cannot connect to server";
    > # get SMTP server welcome
    > $line=<$remote>;
    > print "$line\n";
    >
    > # send HELO
    > print $remote "HELO\n"; # the \n here doesn't seem to work
    >
    > # get reply
    > $line=<$remote>;
    > print "$line\n";
    >
    >
     
    Iceberg, Sep 6, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schroeder
    Replies:
    1
    Views:
    583
    Jim Gibson
    Jan 26, 2005
  2. Replies:
    1
    Views:
    2,830
    Martin Dechev
    Oct 7, 2005
  3. Replies:
    3
    Views:
    943
    John C. Bollinger
    Jan 17, 2005
  4. Porthos
    Replies:
    1
    Views:
    588
    C. M. Sperberg-McQueen
    Jul 27, 2005
  5. Steve Anderson
    Replies:
    3
    Views:
    277
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page