Exemple #1
0
 /**
  * Create server
  *  - bind to port
  *  - listen port
  * @throws ListenException
  * @throws BindException
  */
 function create($blocking = true)
 {
     $this->open();
     $serverSocket = $this->getSocketResource();
     if (!socket_bind($serverSocket, $this->getIp(), $this->getPort())) {
         throw new BindException($this);
     }
     $this->getEventDispatcher()->dispatch(BindEvent::getEventName(), new BindEvent($this, $this));
     if (!socket_listen($serverSocket)) {
         throw new ListenException($this);
     }
     if ($blocking) {
         socket_set_block($serverSocket);
     } else {
         socket_set_nonblock($serverSocket);
     }
     $this->start();
     while ($this->running) {
         $clientSocket = socket_accept($serverSocket);
         if (false == $clientSocket) {
             continue;
         }
         $socket = new Socket($this->getAddressType(), $this->getSocketType(), $this->getTransport(), $this->getEventDispatcher());
         $socket->setSocketResource($clientSocket);
         $socket->getEventDispatcher()->dispatch(NewConnectionEvent::getEventName(), new NewConnectionEvent($socket, $this));
     }
 }
Exemple #2
0
 function __construct(Socket $socket, $message)
 {
     $this->socket = $socket;
     $code = socket_last_error();
     $socketErrorMessage = socket_strerror($code);
     parent::__construct("{$message}. {$socketErrorMessage}.", $code);
     $socket->getEventDispatcher()->dispatch(ExceptionEvent::getEventName(), new ExceptionEvent($socket, $this));
 }
Exemple #3
0
 function __construct($ip, $port, Address $addressType, Type $socketType, Transport $transport, EventDispatcherInterface $eventDispatcher)
 {
     parent::__construct($addressType, $socketType, $transport, $eventDispatcher);
     $this->ip = $ip;
     $this->port = $port;
 }