Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199807

[PHP3] getting info from a socket connection From: php <email protected>
Date: 07/14/98

Sorry, I don't think I was clear on exactly what my problem was last time.
Because php treats a file pointer pointing to a socket connection almost
the same way it treats a file pointer pointing to, say, a text file, I am
having trouble gathering the information I need from a socket connection.

>1. I connect to a socket
> $fp = fsockopen($server, $portnumber);
>
>2. I can use the fgets command to get the first line of the "file", which
>is the buffer.
> fgets($fp, 200)
>That gives me:
> +OK server.name.com POP3 3.3(20) w/IMAP2 client at Mon, 13 Jul
>1998 10:19:05 -0500 (CDT)
-------------------
        After doing this, I then send the server commands, such as "user
        username", "pass password", "list", "retr x", all of which seem to go
        through just fine. But when I try to retrieve the information put out by
        the server by these commands, I cant get commands to work such as fseek
        then fgets, or fpassthru, that would normally work on files such as text
        files.
--------------------
>
>But I cannot read any other lines in the "file", and using the fseek
>command does not offset the number of bytes, but keeps the file pointer
>at
>the first character of the file. And the example in the documentation:
>---------------------------------------------------------
>$fp = fsockopen("www.php.net", 80, &$errno, &$errstr);
> if(!$fp) {
> echo "$errstr ($errno)<br>\n";
> } else {
> while(!feof($fp)) {
> echo fgets($fp,128);
> }
> fclose($fp);
> }
>---------------------------------------------------------
>I can't seem to get to work, no matter how much I work with it. I think
>this problem is because in the while loop, the feof command looks for the
>end of the file, but in a socket connection there is no end of file,
>because the connection if always ready to send or retrieve data.
>
>If anyone knows how I can get the data put out by the server when I am
>using fsockopen(), please reply.

Thanks,

adam <email protected>

Adam Roderick
Product Developments Team
Hypernet Communications, Inc.

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive: http://www.tryc.on.ca/php3.html

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.tryc.on.ca/php3.html