src/Generics/Socket/ServerSocket.php
public function serve(ServiceCallback $callback)
    {
        $this->bind();
        
        $this->listen();
        
        $runOn = true;
        
        while ($runOn) {
            $clientHandle = @socket_accept($this->handle);
            
            if (! is_resource($clientHandle)) {
                $code = socket_last_error($this->handle);
                throw new SocketException(socket_strerror($code), array(), $code);
            }
            
            $address = null;
            $port = 0;
            if (! @socket_getpeername($clientHandle, $address, $port)) {
                $code = socket_last_error($clientHandle);
                throw new SocketException(socket_strerror($code), array(), $code);
            }
            
            $client = new ClientSocket(new Endpoint($address, $port), $clientHandle);
            
            $runOn = boolval($callback->callback($client));
        }
    }
public function serve(ServiceCallback $callback)
    {
        $this->bind();
        
        $this->listen();
        
        $runOn = true;
        
        while ($runOn) {
            $clientHandle = @socket_accept($this->handle);
            
            if (! is_resource($clientHandle)) {
                $code = socket_last_error($this->handle);
                throw new SocketException(socket_strerror($code), array(), $code);
            }
            
            $address = null;
            $port = 0;
            if (! @socket_getpeername($clientHandle, $address, $port)) {
                $code = socket_last_error($clientHandle);
                throw new SocketException(socket_strerror($code), array(), $code);
            }
            
            $client = new ClientSocket(new Endpoint($address, $port), $clientHandle);
            
            $runOn = boolval($callback->callback($client));
        }
    }
Creates a service at the given endpoint

@throws SocketException in case of it is not possible to serve due to binding or listening error