Help with sockets needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • artemio@kdemail.net

    Help with sockets needed

    Hello all!

    I need some help with sockets. I have this code:

    $Connection = fsockopen( "google.com ", 80, $ErrNo, $ErrStr, 30 );

    if($Connection) {

    echo "Connection established\n";

    while(!feof($Co nnection)){

    echo fgets($Connecti on, 128);

    }

    echo "Got some data\n";

    } else {

    echo "Error $ErrNo: $ErrStr\n";

    }

    But it never gets to output anything, it only prints "Connection
    established" and then the script simply gets stuck, it never gets to
    say "Got some data"...

    Any help will be very appreciated.


    Thanks,

    Artemiy.

  • Sjoerd

    #2
    Re: Help with sockets needed


    artemio@kdemail .net wrote:
    echo fgets($Connecti on, 128);
    [...]
    But it never gets to output anything
    That is because google.com does not send anything. Only after you sent
    a request will google.com respond. The fgets waits for ever for a line
    from google.com.

    Comment

    • artemio@kdemail.net

      #3
      Re: Help with sockets needed

      Hello and thanks for your reply!

      Oh sorry, yes, with HTTP it indeed is like this, but here is an example
      for POP3:

      $Connection = fsockopen( "soniccharger.c om", 110, $ErrNo, $ErrStr, 30
      );

      if($Connection) {

      echo "Connection established\n";

      while(!feof($Co nnection)){

      echo fgets($Connecti on, 128);

      }

      echo "We got some data\n";

      } else {

      echo "Error $ErrNo: $ErrStr\n";

      }

      When I run it I get:

      $ php pop3test.php
      Connection established
      +OK Hello there.

      And then it gets stuck... :-/

      Comment

      • Alvaro G. Vicario

        #4
        Re: Help with sockets needed

        *** artemio@kdemail .net escribió/wrote (15 Sep 2006 11:01:41 -0700):
        When I run it I get:
        >
        $ php pop3test.php
        Connection established
        +OK Hello there.
        >
        And then it gets stuck... :-/
        Same as with your Google example, I presume. The POP3 server is awaiting
        your commands.


        --
        -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        ++ Mi sitio sobre programación web: http://bits.demogracia.com
        +- Mi web de humor con rayos UVA: http://www.demogracia.com
        --

        Comment

        Working...