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
$config
optional 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
string
IP address
addressessource public
addresses( )
Gets all IP addresses associated with the current connection.
Returns
array
IP addresses
connectsource public
connect( )
Connects the socket to the given host and port.
Returns
boolean
Success
Throws
SocketException
SocketException
contextsource public
context( )
Gets the connection context.
Returns
null|array
Null when there is no connection, an array when there is.
disconnectsource public
disconnect( )
Disconnects the socket from the current connection.
Returns
boolean
Success
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
$clientOrServer
optional 'client' - Can be one of 'client', 'server'. Default is 'client'.
- boolean
$enable
optional true - Enable or disable encryption. Default is true (enable)
Returns
boolean
True on success
Throws
InvalidArgumentException
When an invalid encryption scheme is chosen.
SocketException
When 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
$length
optional 1024 - Optional buffer length to read; defaults to 1024
Returns
mixed
Socket 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
$state
optional null - Array with key and values to reset
Returns
boolean
True 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
boolean
Success
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