File "class.socket.inc"
Full Path: /home/analogde/www/FTP/Code03/inc/class.socket.inc
File size: 1.47 KB
MIME-type: text/x-php
Charset: utf-8
<?php
//
// $Id: class.socket.inc,v1.0 2004-12-18 12:21a EST Onion Exp $
//
/*
* Socket Class
*
* A very simple class for creating a very simple socket connection.
*/
class Socket {
/*
* Private Property
*/
private $s;
/*
* Constructor
*
* void __construct ( string addr, int port )
*/
public function __construct ( $addr, $port ) {
$this->s = @fsockopen ($addr, $port, $errno, $errstr);
if (!$this->s) {
// debugger crap
$debug = new Debugger (__FILE__, __CLASS__, end (explode ('::', __METHOD__)), __LINE__, 'resource of type stream', gettype ($this->s), array ('this' => $this, 'errno' => $errno, 'errstr' => $errstr));
foot ('<pre>'.htmlentities ($debug->__toString ()).'</pre>');
}
}
/*
* Destructor
*
* void __destruct ( void )
*/
public function __destruct ( ) {
fclose ($this->s);
}
/*
* Public Methods
*/
/*
* Socket::write ()
*
* Writes data to the socket.
*
* void write ( string data )
*/
public function write ( $data ) {
fwrite ($this->s, $data);
}
/*
* Socket::get_line ()
*
* Returns a single line from the socket or false on EOF.
*
* mixed get_line ( void )
*/
public function get_line ( ) {
return fgets ($this->s, 8192);
}
/*
* Socket::get_contents ()
*
* Returns the full contents of the socket (since it was last read).
*
* string get_contents ( void )
*/
public function get_contents ( ) {
for ($data = ''; $line = $this->get_line (); $data .= $line);
return $data;
}
}