note 27754 deleted from function.fsockopen by irchtml

From: Date: Tue, 17 Feb 2004 14:09:01 +0000
Subject: note 27754 deleted from function.fsockopen by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65281@lists.php.net to get a copy of this message
Note Submitter: dan@lovepond.com ---- <? $port=4000; $host="localhost"; $message="test"; $status=senddata($host,$port,$message); print "$status"; function senddata($host,$port,$message) { #takes in account servers that do not return EOF character #send data to server and get back input #function globals $linenumber="2"; #amount of lines to get rid of before we give input $lineamount="1"; #amount of lines to read after we give input $fp = fsockopen("$host", $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)"; } else { for ($i = 1; $i < $linenumber+1; $i++) { fread ($fp,1); $bytes_left = socket_get_status($fp); if ($bytes_left > 0) { fread($fp, $bytes_left[unread_bytes]); } } fputs($fp, "$message\r\n"); for ($i = 1; $i < $lineamount+1; $i++) { $status=fread($fp,1); $bytes_left = socket_get_status($fp); if ($bytes_left > 0) { $status.=fread($fp, $bytes_left[unread_bytes]); } } fclose ($fp); } return $status; } ?> Here is some code to help out abit more with the EOF problem. I had a problem where I needed to strip out so many lines of server input to get back right data i wanted.

« previous php.notes (#65281) next »