/** * Construct method for create server socket by given configuration. * * @param Config $config Network configuration * * @throws Exception Throws when socket was not binded * * @return void */ public function __construct(Config $config) { set_time_limit(0); $this->_stream = stream_socket_server('tcp://' . $config->getIp() . ':' . $config->getPort()); if ($this->_stream === false) { throw new Exception('Could not bind to socket: ' . $config->getIp() . ':' . $config->getPort()); } }
/** * Construct method for create connection to the server. * * @param Config $config Configuration of connection * * @throws Exception Throws when socket was not created * * @return void */ public function __construct(Config $config) { $this->_socket = stream_socket_client('tcp://' . $config->getIp() . ':' . $config->getPort()); if (empty($this->_socket)) { throw new Exception('Socket was not created.'); } }