Class CakeSocket
CakePHP network socket connection class.
Core base class for network communication.
Direct known subclasses
HttpSocketCopyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Located at Cake/Network/CakeSocket.php
Method Detail
__constructsource public
__construct( array $config array() )
Constructor.
Parameters
- array
$configoptional array() - Socket configuration, which will be merged with the base configuration
See
CakeSocket::$_baseConfig_connectionErrorHandlersource protected
_connectionErrorHandler( integer $code , string $message )
socket_stream_client() does not populate errNum, or $errStr when there are connection errors, as in the case of SSL verification failure.
Instead we need to handle those errors manually.
Parameters
- integer
$code - Code.
- string
$message - Message.
_setSslContextsource protected
_setSslContext( string $host )
Configure the SSL context options.
Parameters
- string
$host - The host name being connected to.
addresssource public
address( )
Gets the IP address of the current connection.
Returns
stringIP address
addressessource public
addresses( )
Gets all IP addresses associated with the current connection.
Returns
arrayIP addresses
connectsource public
connect( )
Connects the socket to the given host and port.
Returns
booleanSuccess
Throws
SocketExceptionSocketException
contextsource public
context( )
Gets the connection context.
Returns
null|arrayNull when there is no connection, an array when there is.
disconnectsource public
disconnect( )
Disconnects the socket from the current connection.
Returns
booleanSuccess
enableCryptosource public
enableCrypto( string $type , string $clientOrServer 'client' , boolean $enable true )
Encrypts current stream socket, using one of the defined encryption methods.
Parameters
- string
$type - Type which can be one of 'sslv2', 'sslv3', 'sslv23' or 'tls'.
- string
$clientOrServeroptional 'client' - Can be one of 'client', 'server'. Default is 'client'.
- boolean
$enableoptional true - Enable or disable encryption. Default is true (enable)
Returns
booleanTrue on success
Throws
InvalidArgumentExceptionWhen an invalid encryption scheme is chosen.
SocketExceptionWhen attempting to enable SSL/TLS fails.
See
stream_socket_enable_cryptoreadsource public
read( integer $length 1024 )
Reads data from the socket. Returns false if no data is available or no connection could be established.
Parameters
- integer
$lengthoptional 1024 - Optional buffer length to read; defaults to 1024
Returns
mixedSocket data
resetsource public
reset( array $state null )
Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)
Parameters
- array
$stateoptional null - Array with key and values to reset
Returns
booleanTrue on success
setLastErrorsource public
setLastError( integer $errNum , string $errStr )
Sets the last error.
Parameters
- integer
$errNum - Error code
- string
$errStr - Error string
writesource public
write( string $data )
Writes data to the socket.
Parameters
- string
$data - The data to write to the socket
Returns
booleanSuccess
Properties summary
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-CakeSocket.html