<?php
/**
 * Open Source - Content Managment System
 * Next Generation v2
 * @Coder:  Mutzii
 * @copyright  Copyright (c) 2012-2013 by Mutzii
 * File:  socket.class.php
 * @Description:  
      Nicht getestet, nicht im CMS intigriert.	  
 */

class socket
{
   
 var $socket;
 var $addr;
 var $port;
 var $error; 
 
 
	   public function socket($ipaddr,$port)
	   {
	        $this->socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
            $this->addr   = $ipaddr;
            $this->port   = $port;

            if($this->socket === false)
			{
		        $this->error_fill(socket_strerror(socket_last_error()));
			}
			
	   }
	   
	   public function connect()
	   {
	       if(empty($this->error))
           {
                $result = socket_connect($this->socket,$this->addr,$this->port);
                if($result === false)
                {
                  return $this->error_fill(socket_strerror(socket_last_error($this->socket)));
                }else{
                  return true;
                }				

           }else{
               return  $this->error_output();
           }		      
	   }
	   
	   public function write($string)
	   {
	     socket_write($this->socket,$string,strlen($string));
	   }
	   
	   public function read()
	   {
	     // Prototype: Wird für dieses CMS wahrscheinlich nicht gebraucht...
	     while($out = socket_read($this->socket,2048))
		 {
		    echo $out;
		 }
		 
	   }
	   
	   public function error_fill($error)
	   {
	     $this->error = $error;
	   }

	   public function error_output()
	   {
	     return $this->error;
	   }
	   
}








?>
