www.webdeveloper.com
Results 1 to 10 of 10

Thread: Read from socket until no more data

  1. #1
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42

    Read from socket until no more data

    Hi,

    I am having a problem with socket_read(). Socket_read wants a secound parm to tell it how much data to read. The problem is that there is no fixed amount. I want it to read as much as there is to read. I have tried putting 0 and not including that parm, it just complains and fails.

    Is there any way I can just read until there is no more data?

    Thanks,
    Chris

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    http://php.net/manual/en/function.socket-recv.php

    use $buffer as the string you want to store the info to, first note explains most of it.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42
    Quote Originally Posted by scragar
    http://php.net/manual/en/function.socket-recv.php

    use $buffer as the string you want to store the info to, first note explains most of it.
    THANKS!!!

    Thanks Scragar... For some reason you are always the first one to solve my stuff...

    (edit: see below)

    Chris
    Last edited by aximbigfan; 08-14-2008 at 10:39 PM.

  4. #4
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42
    Erm... How does the syntax go?

    I have this: $message = socket_recv($spawn, $message);
    but get this:
    Warning: socket_recv() expects exactly 4 parameters, 2 given in /opt/SocketServer.php on line 125


    If I supply a len, isn't it just going to chop like the other function?

    Thanks,
    Chris

  5. #5
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    PHP Code:
    $fullResult '';
    while(
    false !== socket_recv($spawn$message1024,0)){
      if(
    $message != null)
        
    $fullResult .= $message;
    };
    echo 
    $fullResult
    EDITED: removed a few characters from the second line that throw an error
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  6. #6
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42
    Quote Originally Posted by scragar
    PHP Code:
    $fullResult '';
    while(
    false !== socket_recv($spawn$message1024,0)){
      if(
    $message != null)
        
    $fullResult .= $message;
    };
    echo 
    $fullResult
    EDITED: removed a few characters from the second line that throw an error
    Ok, I see...

    Thanks a bunch!

    Edit: see below

    Chris
    Last edited by aximbigfan; 08-14-2008 at 11:07 PM.

  7. #7
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42
    Hi Scragar, sorry to bother you again,

    This part is failing. It just hangs.

    PHP Code:
    //Read sent data and report
        
    echo "Reading message...         ";
        
    $message "";
            while (
    false !== socket_recv($spawn$part_message10240))
            {
            if (
    $part_message != NULL)
                
    $message .= $part_message;
            }
            
        if (!
    $message)
            echo 
    "Error!\n";
        else
            echo 
    "OK\n"
    Chris

  8. #8
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    try this and let me know the result
    PHP Code:
    $len socket_recv($spawn$part_message1024MSG_TRUNC);
    echo 
    $len
    I'm sorry that it's not much, but I'm curious to see how the length is altered by that flag(since it's completely undocumented), and I don't have the tools to test it myself for a little while(not on any of my machines and I don't think my neighbour will like me installing strange stuff on her's when I'm supposed to be fixing it).
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  9. #9
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42
    I get this:
    Warning: socket_recv() expects parameter 4 to be long, string given in /opt/SocketServer.php on line 125

    when that flag is set to 4 it runs, but does NOT ignore the transfer limit.

    HOWEVER:::
    PHP Code:
        $message socket_recv($spawn$part_message10240);
        
    $message $part_message
    Seems to collect data... edit: but it does not ignore the limit.

    Chris
    Last edited by aximbigfan; 08-15-2008 at 06:16 PM.

  10. #10
    Join Date
    Mar 2008
    Location
    Chesterfield, MO
    Posts
    42
    bump

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles