<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def listen(self, port=None):
 """Start listening for incoming connections. A request handler must have already been specified with ``TChannel.host``. :param port: An explicit port to listen on. This is unnecessary when advertising on Hyperbahn. :returns: Returns immediately. :raises AlreadyListeningError: If listen was already called. """


        if self.is_listening():
            raise AlreadyListeningError(
                "listen has already been called"
            )

        if port:
            assert not self._port, "Port has already been set."
            self._port = int(port)

        assert self._handler, "Call .host with a RequestHandler first"
        server = TChannelServer(self)

        bind_sockets_kwargs = {
            'port': self._port,
            # ipv6 causes random address already in use (socket.error w errno
            # == 98) when getaddrinfo() returns multiple values
            # @see https://github.com/uber/tchannel-python/issues/256
            'family': socket.AF_INET,
        }
        if self._reuse_port is True:
            # allow multiple processes to share the same port,
            # this is really useful in a world where services launch N
            # processes per container/os-space, where N is
            # the amount of cpus for example
            bind_sockets_kwargs['reuse_port'] = True

        sockets = bind_sockets(**bind_sockets_kwargs)
        assert sockets, "No sockets bound for port %d" % self._port

        # If port was 0, the OS probably assigned something better.
        self._port = sockets[0].getsockname()[1]

        server.add_sockets(sockets)

        # assign server so we don't listen twice
        self._server = server