Net.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class Net extends BaseObject {
  3.    var $server;
  4.    var $port;
  5.    var $connnected;
  6.    var $connection_handle;
  7.    Function Net() {
  8.       $this->BaseObject( 'Net' );
  9.       $this->server              = '';
  10.       $this->port                = '';
  11.       $this->connected           = 0;
  12.       $this->connection_handle   = undef;
  13.    }
  14.    Function Open()      { return $this->Connect(); }
  15.    Function Connect()   {
  16.       $this->connection_handle =
  17.          fsockopen( 
  18.             $this->server,
  19.             $this->port,
  20.             $error_number,
  21.             $error_string
  22.          );
  23.       if ( ! $this->connection_handle ) {
  24.          return Array( 
  25.             false, 
  26.             'Could not connect : ' . 
  27.                $error_number, ' - ' . $error_string 
  28.          );
  29.       }
  30.       $this->connected = true;
  31.    }
  32.    Function Close()        { return $this->Disconnect(); }
  33.    Function Disconnect()   {
  34.       return fclose( $this->connection_handle );
  35.    }
  36.    Function ReadLine( $buffer_len = 2048 ) {
  37.       if ( $this->connected == true ) {
  38.          return fgets( $this->connection_handle, $buffer_len );
  39.       }
  40.    }
  41.    Function SendLine( $line ) {
  42.       if ( $this->connected == true ) {
  43.          return fputs( $this->connection_handle, $line );
  44.       }
  45.       return 0;
  46.    }
  47. }
  48. ?>