File: src/Generics/Socket/SecureClientSocket.php

Recommend this page to a friend!
  Classes of Maik Greubel  >  PHP Generics  >  src/Generics/Socket/SecureClientSocket.php  >  Download  
File: src/Generics/Socket/SecureClientSocket.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Test enhancement
Date: 1 year ago
Size: 1,950 bytes
 

Contents

Class file image Download
<?php
/**
 * This file is part of the PHP Generics package.
 *
 * @package Generics
 */
namespace Generics\Socket;

/**
 * This class provides a secure socket client
 *
 * @author Maik Greubel <greubel@nkey.de>
 */
class SecureClientSocket extends SecureSocket
{

   
/**
     * Whether the socket is connected
     *
     * @var boolean
     */
   
private $conntected;

   
/**
     * Create a new client socket
     *
     * @param Endpoint $endpoint
     * The endpoint to use
     * @param resource $clientHandle
     * optional existing client handle
     */
   
public function __construct(Endpoint $endpoint, $clientHandle = null)
    {
       
$this->endpoint = $endpoint;
       
$this->handle = $clientHandle;
       
$this->conntected = false;
       
        if (!
is_resource($clientHandle)) {
           
parent::__construct($endpoint);
        }
    }

   
/**
     * Connect to remote endpoint
     *
     * @throws SocketException
     */
   
public function connect()
    {
       
$this->conntected = true;
    }

   
/**
     * Disconnects the socket
     *
     * @throws SocketException
     */
   
public function disconnect()
    {
        if (!
$this->conntected) {
            throw new
SocketException("Socket is not connected");
        }
       
       
$this->close();
    }

   
/**
     * Whether the client is connected
     *
     * @return bool
     */
   
public function isConnected(): bool
   
{
        return
$this->conntected;
    }

   
/**
     *
     * @see \Generics\Socket\ClientSocket::disconnect()
     */
   
public function close()
    {
       
parent::close();
       
$this->conntected = false;
    }

   
/**
     *
     * {@inheritdoc}
     * @see \Generics\Socket\Socket::isWriteable()
     */
   
public function isWriteable(): bool
   
{
        if (!
$this->isConnected()) {
            return
false;
        }
       
        return
parent::isWriteable();
    }
}


For more information send a message to info at phpclasses dot org.