Loading Please wait...

zSocketClient Class Reference
[Socket Operations]

SocketClient Class. More...

Inheritance diagram for zSocketClient:

Inheritance graph
[legend]
Collaboration diagram for zSocketClient:

Collaboration graph
[legend]

Public Member Functions

 zSocketClient ($host=null, $port=null, $timeout=null)
 __construct ($host=null, $port=null, $timeout=null)
 setHost ($hostName)
 Sets the Host Name.
 getHost ()
 Get the Host Name.
 setPort ($port)
 set the Connection Port
 getPort ()
 Get the Conection Port.
 setTimeOut ($timeOut)
 Set the Connection Timeout.
 getTimeOut ()
 Returns the Timeout.
 setSeparator ($sep)
 Set the separatotor
or
.
 useUDP ($flag=true)
 Sets Wheather to use UDP Connection or not.
 isUDP ()
 Returns Wheather teh Connection is UDP or not.
 useTCP ($flag=true)
 Wheather to use TCP or not.
 isTCP ()
 Returns boolean vlue wheather or not The Connection is TCP.
 useSSL ($flag=true)
 Use SSL in the Connection.
 isSSL ()
 Returns Boolean value wheather the Connection is a SSL Connection.
 useTLS ($flag=true)
 Use TLS Connection.
 isTLS ()
 Checks wheather or not it is a TLS Connection.
 connect ()
 Connect the Socket with the Server.
 isConnected ()
 Returns Boolean value wheather socket is Connected or not.
 isConnectable ()
 Checks Wheathers its Connectable or not.
 send ($data)
 Send the Data to the Server.
 receive ($maxLen=0)
 Reacieve Data from the server.
 disconnect ()
 Disconnect from the Server.
 __destruct ()
 Automatically Disconnect upon destruct.

Data Fields

 $host
 $port
 $timeout
 $sep
 $connected
 $map
 $protocol
 $handle
 $cnv
 $conversation

Detailed Description

SocketClient Class.

all kinds of sockets can inherits from this Class. it provides abstraction all native socket level operations

Definition at line 30 of file socket.php.


Constructor & Destructor Documentation

zSocketClient::__construct ( host = null,
port = null,
timeout = null 
)

Definition at line 45 of file socket.php.

References $host, $port, and $timeout.

00045                                                              {
00046     $this->host = $host;
00047     $this->port = $port;
00048     $this->timeout = $timeout;
00049     $this->sep = "\r\n";
00050     $this->protocol = 'tcp';
00051     $this->conversation = new stdClass();
00052     $this->conversation->client = array();
00053     $this->conversation->server = array();
00054   }

zSocketClient::__destruct (  ) 

Automatically Disconnect upon destruct.

Reimplemented from zCore.

Definition at line 272 of file socket.php.

References disconnect().

00272                        {
00273     $this->disconnect();
00274   }

Here is the call graph for this function:


Member Function Documentation

zSocketClient::zSocketClient ( host = null,
port = null,
timeout = null 
)

Definition at line 42 of file socket.php.

References $host, $port, $timeout, and zCore::__construct().

00042                                                                {
00043     $this->__construct($host, $port, $timeout);
00044   }

Here is the call graph for this function:

zSocketClient::setHost ( hostName  ) 

Sets the Host Name.

Parameters:
$hostName string

Definition at line 60 of file socket.php.

00060                              {
00061     $this->host = $hostName;
00062   }

zSocketClient::getHost (  ) 

Get the Host Name.

Definition at line 67 of file socket.php.

00067                     {
00068     return $this->host;
00069   }

zSocketClient::setPort ( port  ) 

set the Connection Port

Parameters:
$port int

Definition at line 75 of file socket.php.

References $port.

00075                          {
00076     $this->port = $port;
00077   }

zSocketClient::getPort (  ) 

Get the Conection Port.

Definition at line 82 of file socket.php.

00082                     {
00083     return $this->port;
00084   }

zSocketClient::setTimeOut ( timeOut  ) 

Set the Connection Timeout.

Parameters:
$timeOut int

Definition at line 90 of file socket.php.

00090                                {
00091     $this->timeout = $timeOut;
00092   }

zSocketClient::getTimeOut (  ) 

Returns the Timeout.

Returns:
int

Definition at line 98 of file socket.php.

00098                        {
00099     return $this->timeout;
00100   }

zSocketClient::setSeparator ( sep  ) 

Set the separatotor
or
.

Parameters:
$sep string

Definition at line 106 of file socket.php.

References $sep.

00106                              {
00107     $this->sep = $sep;
00108   }

zSocketClient::useUDP ( flag = true  ) 

Sets Wheather to use UDP Connection or not.

Parameters:
$flag boolean

Definition at line 114 of file socket.php.

00114                                {
00115     $this->protocol = $flag ? 'udp' : 'tcp';
00116   }

zSocketClient::isUDP (  ) 

Returns Wheather teh Connection is UDP or not.

Returns:
booleans

Definition at line 122 of file socket.php.

00122                   {
00123     return ($this->protocol == 'udp');
00124   }

zSocketClient::useTCP ( flag = true  ) 

Wheather to use TCP or not.

Parameters:
$flag booleans

Definition at line 130 of file socket.php.

00130                              {
00131     $this->protocol = $flag ? 'tcp' : $this->protocol;
00132   }

zSocketClient::isTCP (  ) 

Returns boolean vlue wheather or not The Connection is TCP.

Returns:
boolean

Definition at line 138 of file socket.php.

00138                   {
00139     return ($this->protocol == 'tcp');
00140   }

zSocketClient::useSSL ( flag = true  ) 

Use SSL in the Connection.

Definition at line 145 of file socket.php.

00145                                {
00146     $this->protocol = $flag ? 'ssl' : '';
00147   }

zSocketClient::isSSL (  ) 

Returns Boolean value wheather the Connection is a SSL Connection.

Returns:
boolean

Definition at line 153 of file socket.php.

00153                   {
00154     return ($this->protocol == 'ssl');
00155   }

zSocketClient::useTLS ( flag = true  ) 

Use TLS Connection.

Parameters:
$flag unknown_type

Definition at line 161 of file socket.php.

00161                              {
00162     $this->protocol = $flag ? 'tls' : '';
00163   }

zSocketClient::isTLS (  ) 

Checks wheather or not it is a TLS Connection.

Returns:
boolean

Definition at line 169 of file socket.php.

00169                   {
00170     return ($this->protocol == 'tls');
00171   }

zSocketClient::connect (  ) 

Connect the Socket with the Server.

Definition at line 176 of file socket.php.

References zLogger::debug(), zLogger::error(), isConnectable(), isConnected(), and perror().

Referenced by zLogClient::__construct().

00176                     {
00177     if(!$this->isConnectable()){
00178       perror("<code>zigmoyd.socket.connect</code><br />Sorry Server not Connectable");
00179       exit;
00180     }
00181     if(!$this->isConnected()){
00182       if(!$this->handle = @pfsockopen($this->host, $this->port, $errNo, $errStr, $this->timeout)){
00183         perror("<code>zigmoyd.socket.connect</code><br />Failed to Connect with $this->host on Port $this->port<br />Error No: $errNo<br />Error Text: $errStr");
00184         if(class_exists('zLogger'))zLogger::error("Failed to Connect with Host $this->host on Port $this->port Error: ($errNo) $errStr", 'socket.connect');
00185         $this->connected = false;
00186       }else{
00187         if(class_exists('zLogger'))zLogger::debug("Successfully Connected to Host $this->host on Port $this->port<br />Error No: $errNo<br />Error Text: $errStr", 'socket.connect');
00188         $this->connected = true;
00189       }
00190     }
00191     return $this->connected;
00192   }

Here is the call graph for this function:

zSocketClient::isConnected (  ) 

Returns Boolean value wheather socket is Connected or not.

Returns:
boolean

Definition at line 198 of file socket.php.

Referenced by connect().

00198                         {
00199     return $this->connected;
00200   }

zSocketClient::isConnectable (  ) 

Checks Wheathers its Connectable or not.

Returns:
boolean

Definition at line 206 of file socket.php.

References zLogger::error(), and perror().

Referenced by connect().

00206                           {
00207     if(strlen($this->protocol) <= 1){
00208       perror('<code>zigmoyd.socket.isConnectable</code><br />Invalid Protocol');
00209       if(class_exists('zLogger'))zLogger::error('Invalid Protocol', 'zigmoyd.socket');
00210       return false;
00211     }
00212     if(strlen($this->host) <= 1){
00213       perror('<code>zigmoyd.socket.isConnectable</code><br />Invalid Host');
00214       if(class_exists('zLogger'))zLogger::error('Invalid Host', 'zigmoyd.socket');
00215       return false;
00216     }
00217     if(strlen($this->port) <= 1){
00218       perror('<code>zigmoyd.socket.isConnectable</code><br />Invalid Port');
00219       if(class_exists('zLogger'))zLogger::error('Invalid Port', 'zigmoyd.socket');
00220       return false;
00221     }
00222     if(!$this->timeout){
00223       $this->timeout = 30;
00224     }
00225     return true;
00226   }

Here is the call graph for this function:

zSocketClient::send ( data  ) 

Send the Data to the Server.

returns Success value in Boolean

Parameters:
$data string
Returns:
boolean

Definition at line 233 of file socket.php.

References perror().

Referenced by zLogClient::write().

00233                       {
00234     $this->conversation->client[] = $data;
00235     fflush($this->handle);
00236     $ret = fwrite($this->handle, $data.$this->sep);
00237     if(!$ret)perror('<code>zigmoyd.socket.send</code><br />Failed to Write on Sicket');
00238     return $ret;
00239   }

Here is the call graph for this function:

zSocketClient::receive ( maxLen = 0  ) 

Reacieve Data from the server.

Parameters:
$maxLen int

Definition at line 245 of file socket.php.

00245                              {
00246     $return = '';
00247     while(is_string(($ch = fgetc($this->handle)))){
00248       if($maxLen != 1){
00249         $return .= $ch;
00250         --$maxLen;
00251       }
00252     }
00253     $this->conversation->server[] = $return;
00254     return $return;
00255   }

zSocketClient::disconnect (  ) 

Disconnect from the Server.

Definition at line 260 of file socket.php.

References zLogger::debug().

Referenced by __destruct().

00260                        {
00261     if(is_resource($this->handle)){
00262       if(class_exists('zLogger'))zLogger::debug("Closing Socket Connection as not yet Closed", "socket.disconnect");
00263       fclose($this->handle);
00264     }else{
00265       if(class_exists('zLogger'))zLogger::debug("NOT Closing Socket Connection as already Closed", "socket.disconnect");
00266     }
00267   }

Here is the call graph for this function:


Field Documentation

zSocketClient::$host

Definition at line 31 of file socket.php.

Referenced by __construct(), and zSocketClient().

zSocketClient::$port

Definition at line 32 of file socket.php.

Referenced by __construct(), setPort(), and zSocketClient().

zSocketClient::$timeout

Definition at line 33 of file socket.php.

Referenced by __construct(), and zSocketClient().

zSocketClient::$sep

Definition at line 34 of file socket.php.

Referenced by setSeparator().

zSocketClient::$connected

Definition at line 35 of file socket.php.

zSocketClient::$map

Definition at line 36 of file socket.php.

zSocketClient::$protocol

Definition at line 37 of file socket.php.

zSocketClient::$handle

Definition at line 38 of file socket.php.

zSocketClient::$cnv

Definition at line 39 of file socket.php.

zSocketClient::$conversation

Definition at line 40 of file socket.php.


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:54:32 2008 for zigmoyd.kdevelop by doxygen 1.5.6