All pastes #27937 Raw Edit

Untitled

public text v1 · immutable
#27937 ·published 2005-11-08 03:21 UTC
rendered paste body
chat.php: 
<?php
include('client.cls.php');
$client = new server('192.168.1.3', '9000');
$client->run();
?>

client.cls.php:
<?php
class server{
  public $connection;
  public $ip;
  public $port;
  public $crlf;
  public $version;
  public $read;
  private $myconn;
  function server($ip,$port){
    $this->ip             = $ip;
    $this->port           = $port;
    $this->socket         = '';
    $this->version        = '1.0.0';
    $this->crlf           = "\r\n";
    set_time_limit(0);
    @ob_end_clean();
  }     
  
  function create_socket(){
    $this->connection = fsockopen($this->ip, $this->port);
    if(!$this->connection){
      $this->logit('ERROR STARTING SOCKET');
      die();
    }
  }

  function set_input($input){
    $this->myconn['input'] = $input;
    return true;
  }

  function get_input(){
    return $this->myconn['input'];
  }

  function reset_input(){
    $this->myconn['input'] = '';
    return true;
  }

  function read_socket(){
    return trim(fgets($this->connection),4096);
  }

  function socket_end(){
    return fclose($this->connection);
  }

  function send($msg){
    return fwrite($this->connection, $msg);
  }

  function logit($msg){
    echo '['.date('m/d/Y H:i:s').'] '.$msg."\n";
  }

  function run(){
    $this->create_socket();
    $this->logit('Itrebal Creations PHP Client Running on Port '.$this->port);
    $this->send('#nick itrebal2');
    while(!feof($this->connection)){
      $input = $this->read_socket();
      $this->logit('<- '.$input);
      $this->set_input($input);
      echo 'LOOPED';
    }
  }
}
?>