php socket question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sticks

    php socket question

    hello

    i want to be able to send a packet to a http server and receive the
    response, but i'm not quite sure how to do it. i thought of using
    sockets, and although i have worked out how to send data to the http
    server, i have no idea how to receive the responses.

    any help wuld be greatly appreciated.

    this is what i've got so far. i know that the server is receiving the
    data because i have employed this technique before, only previously i
    did not need to receive the response.

    <?php

    function login()
    {
    $data = "POST /admin/default.asp HTTP/1.1\r\n";
    $data .= etc etc etc

    $socket = socket_create(A F_INET,SOCK_STR EAM,SOL_TCP);
    $connection = socket_connect( $socket,'(*IP ADDRESS*)','80' );

    socket_write($s ocket,$data);
    socket_close($s ocket);
    }

    login();

    ?>
  • Zurab Davitiani

    #2
    Re: php socket question

    Sticks wrote:
    [color=blue]
    > <?php
    >
    > function login()
    > {
    > $data = "POST /admin/default.asp HTTP/1.1\r\n";
    > $data .= etc etc etc
    >
    > $socket = socket_create(A F_INET,SOCK_STR EAM,SOL_TCP);
    > $connection = socket_connect( $socket,'(*IP ADDRESS*)','80' );
    >
    > socket_write($s ocket,$data);
    > socket_close($s ocket);
    > }
    >
    > login();
    >
    > ?>[/color]

    Avoid using HTTP 1.1 - in my experience, PHP4 doesn't handle the chunked
    transfer encoding very well. I don't know if they have sorted this out in
    later versions though. The examples you are looking for are here:


    Comment

    • sinan

      #3
      Re: php socket question

      Take a look at the php manual item about fsockopen() at www.php.net .
      There are examples too.

      Comment

      • Chung Leong

        #4
        Re: php socket question

        "Sticks" <barton_finkle@ hotmail.com> wrote in message
        news:41062a37$0 $22405$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
        > hello
        >
        > i want to be able to send a packet to a http server and receive the
        > response, but i'm not quite sure how to do it. i thought of using
        > sockets, and although i have worked out how to send data to the http
        > server, i have no idea how to receive the responses.
        >
        > any help wuld be greatly appreciated.
        >
        > this is what i've got so far. i know that the server is receiving the
        > data because i have employed this technique before, only previously i
        > did not need to receive the response.[/color]

        See http://www.php.net/stream_context_create


        --
        Obey the Clown - http://www.conradish.net/bobo/


        Comment

        Working...