[olug] PHP tcp devel

troehr at nj-onramp.com troehr at nj-onramp.com
Tue Jan 13 22:04:00 UTC 2004


The only issue I see with the code is that you are using eof() instead of
feof(). Take a look at:

http://www.php.net/manual/en/function.feof.php

Tom

Quoting Ryan O'Rourke <ryano at ch-gifts.com>:

> On Tue, 2004-01-13 at 11:41, troehr at nj-onramp.com wrote:
> > TCP/IP Sockets seems to be supported in PHP 4.1 and greater.
> > 
> > http://www.php.net/manual/en/function.socket-listen.php
> 
> The socket functions listed on that page should work to open, close,
> listen for, and send data across TCP sockets? 
> 
> Here's what the developer is trying to do:
> $length = strlen($output);
> $hexlength = dechex($length);
> $hexlength1 = "\x95";
> $header = "\x02\x46\x44\x02\x00$hexlength1";
> $footer = "\x03\x46\x44\x03";
> $header .= "$output$footer";
> $output = "$header";
> 
> 
> $host = "ww.xx.yy.zz";
> $port = XXXXX;
> 
> //Open a client connection
> $fp = fsockopen($host, $port, $errno, $errstr);
> 
> if (!$fp){
> $result = "Error: Could not open socket connection";
> }else{
> //Write the user string to the socket
> fputs ($fp, $output, strlen($output));
> //get the result
> while(!eof($fp))
> {
> $result .= fgets($fp, 1024);
> }
> //close the connection
> fclose($fp);
> }
> 
> I guess the fput function works and data gets sent, but when the
> response is sent it hangs. In a way, it's like the code doesn't
> recognize an "EOF"....
> Like I said, I'm not a developer so any help or pointers would be
> appreciated!
> 
> Thanks.
> 
> -- Ryan
> 
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
> 




More information about the OLUG mailing list