

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 | |
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.
| 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 }

| 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 }

| zSocketClient::setHost | ( | $ | hostName | ) |
| zSocketClient::getHost | ( | ) |
| zSocketClient::setPort | ( | $ | port | ) |
set the Connection Port
| $port | int |
Definition at line 75 of file socket.php.
References $port.
00075 { 00076 $this->port = $port; 00077 }
| zSocketClient::getPort | ( | ) |
| zSocketClient::setTimeOut | ( | $ | timeOut | ) |
| zSocketClient::getTimeOut | ( | ) |
| zSocketClient::setSeparator | ( | $ | sep | ) |
Set the separatotor
or
.
| $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.
| $flag | boolean |
Definition at line 114 of file socket.php.
| zSocketClient::isUDP | ( | ) |
Returns Wheather teh Connection is UDP or not.
Definition at line 122 of file socket.php.
| zSocketClient::useTCP | ( | $ | flag = true |
) |
| zSocketClient::isTCP | ( | ) |
Returns boolean vlue wheather or not The Connection is TCP.
Definition at line 138 of file socket.php.
| zSocketClient::useSSL | ( | $ | flag = true |
) |
| zSocketClient::isSSL | ( | ) |
Returns Boolean value wheather the Connection is a SSL Connection.
Definition at line 153 of file socket.php.
| zSocketClient::useTLS | ( | $ | flag = true |
) |
| zSocketClient::isTLS | ( | ) |
Checks wheather or not it is a TLS Connection.
Definition at line 169 of file socket.php.
| 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 }

| zSocketClient::isConnected | ( | ) |
Returns Boolean value wheather socket is Connected or not.
Definition at line 198 of file socket.php.
Referenced by connect().
| zSocketClient::isConnectable | ( | ) |
Checks Wheathers its Connectable or not.
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 }

| zSocketClient::send | ( | $ | data | ) |
Send the Data to the Server.
returns Success value in Boolean
| $data | string |
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 }

| zSocketClient::receive | ( | $ | maxLen = 0 |
) |
Reacieve Data from the server.
| $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 }

| zSocketClient::$host |
| zSocketClient::$port |
Definition at line 32 of file socket.php.
Referenced by __construct(), setPort(), and zSocketClient().
| zSocketClient::$timeout |
| zSocketClient::$sep |
| 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.
1.5.6