Formatting output Plese Wait...
SocketClient Class.
More...
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( unknown $host = null
, unknown $port = null
, unknown $timeout = null
)
Definition at line 45 of file socket.php.
References $host, $port, and $timeout.
Show Source00045 {
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 }
Top
zSocketClient::__destruct( )
Member Function Documentation
zSocketClient::zSocketClient( unknown $host = null
, unknown $port = null
, unknown $timeout = null
)
zSocketClient::setHost( string $hostName )
Sets the Host Name.
- Parameters:
-
Definition at line 60 of file socket.php.
Show Source00060 {
00061 $this->host = $hostName;
00062 }
Top
zSocketClient::getHost( )
Get the Host Name.
Definition at line 67 of file socket.php.
Show Source00067 {
00068 return $this->host;
00069 }
Top
zSocketClient::setPort( int $port )
set the Connection Port
- Parameters:
-
Definition at line 75 of file socket.php.
References $port.
Show Source00075 {
00076 $this->port = $port;
00077 }
Top
zSocketClient::getPort( )
Get the Conection Port.
Definition at line 82 of file socket.php.
Show Source00082 {
00083 return $this->port;
00084 }
Top
zSocketClient::setTimeOut( int $timeOut )
Set the Connection Timeout.
- Parameters:
-
Definition at line 90 of file socket.php.
Show Source00090 {
00091 $this->timeout = $timeOut;
00092 }
Top
zSocketClient::getTimeOut( )
Returns the Timeout.
- Returns:
- int
Definition at line 98 of file socket.php.
Show Source00098 {
00099 return $this->timeout;
00100 }
Top
zSocketClient::setSeparator( string $sep )
Set the separatotor
or
.
- Parameters:
-
Definition at line 106 of file socket.php.
References $sep.
Show Source00106 {
00107 $this->sep = $sep;
00108 }
Top
zSocketClient::useUDP( boolean $flag = true
)
Sets Wheather to use UDP Connection or not.
- Parameters:
-
Definition at line 114 of file socket.php.
Show Source00114 {
00115 $this->protocol = $flag ? 'udp' : 'tcp';
00116 }
Top
Returns Wheather teh Connection is UDP or not.
- Returns:
- booleans
Definition at line 122 of file socket.php.
Show Source00122 {
00123 return ($this->protocol == 'udp');
00124 }
Top
zSocketClient::useTCP( booleans $flag = true
)
Wheather to use TCP or not.
- Parameters:
-
Definition at line 130 of file socket.php.
Show Source00130 {
00131 $this->protocol = $flag ? 'tcp' : $this->protocol;
00132 }
Top
Returns boolean vlue wheather or not The Connection is TCP.
- Returns:
- boolean
Definition at line 138 of file socket.php.
Show Source00138 {
00139 return ($this->protocol == 'tcp');
00140 }
Top
zSocketClient::useSSL( booleans $flag = true
)
Use SSL in the Connection.
Definition at line 145 of file socket.php.
Show Source00145 {
00146 $this->protocol = $flag ? 'ssl' : '';
00147 }
Top
Returns Boolean value wheather the Connection is a SSL Connection.
- Returns:
- boolean
Definition at line 153 of file socket.php.
Show Source00153 {
00154 return ($this->protocol == 'ssl');
00155 }
Top
zSocketClient::useTLS( unknown_type $flag = true
)
Use TLS Connection.
- Parameters:
-
Definition at line 161 of file socket.php.
Show Source00161 {
00162 $this->protocol = $flag ? 'tls' : '';
00163 }
Top
Checks wheather or not it is a TLS Connection.
- Returns:
- boolean
Definition at line 169 of file socket.php.
Show Source00169 {
00170 return ($this->protocol == 'tls');
00171 }
Top
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().
Show Source00176 {
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 }
Top
zSocketClient::isConnected( )
Returns Boolean value wheather socket is Connected or not.
- Returns:
- boolean
Definition at line 198 of file socket.php.
Referenced by connect().
Show Source00198 {
00199 return $this->connected;
00200 }
Top
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().
Show Source00206 {
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 }
Top
zSocketClient::send( string $data )
Send the Data to the Server.
returns Success value in Boolean
- Parameters:
-
- Returns:
- boolean
Definition at line 233 of file socket.php.
References perror().
Referenced by zLogClient::write().
Show Source00233 {
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 }
Top
zSocketClient::receive( int $maxLen = 0
)
Reacieve Data from the server.
- Parameters:
-
Definition at line 245 of file socket.php.
Show Source00245 {
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 }
Top
zSocketClient::disconnect( )
Disconnect from the Server.
Definition at line 260 of file socket.php.
References zLogger::debug().
Referenced by __destruct().
Show Source00260 {
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 }
Top
Field Documentation
zSocketClient::$connected
zSocketClient::$conversation
The documentation for this class was generated from the following file: