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

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

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:
    698
    Jim Gibson
    Jan 26, 2005
  2. Replies:
    1
    Views:
    3,178
    Martin Dechev
    Oct 7, 2005
  3. Replies:
    3
    Views:
    1,165
    John C. Bollinger
    Jan 17, 2005
  4. Porthos
    Replies:
    1
    Views:
    668
    C. M. Sperberg-McQueen
    Jul 27, 2005
  5. Chad Paquette

    getenv and carriage returns

    Chad Paquette, Feb 4, 2004, in forum: C Programming
    Replies:
    5
    Views:
    798
    Martin Dickopp
    Feb 5, 2004
  6. freesoft_2000

    Spacings And Carriage Returns

    freesoft_2000, Sep 7, 2006, in forum: Java
    Replies:
    3
    Views:
    568
    Tor Iver Wilhelmsen
    Sep 8, 2006
  7. Steve Anderson
    Replies:
    3
    Views:
    447
    Steve Anderson
    Jun 21, 2004
  8. Joseph Czapski

    CGI.pm and lost carriage returns

    Joseph Czapski, Jul 20, 2006, in forum: Perl Misc
    Replies:
    20
    Views:
    661
    Alan J. Flavell
    Jul 22, 2006
Loading...