'Invoke the given callback with a client protocol and a server protocol
which have been connected to each other.'

def _connectedClientAndServerTest(self, callback):

    serverFactory = MyServerFactory()
    serverConnMade = defer.Deferred()
    serverFactory.protocolConnectionMade = serverConnMade
    port = reactor.listenTCP(0, serverFactory, interface='127.0.0.1')
    self.addCleanup(port.stopListening)
    portNumber = port.getHost().port
    clientF = MyClientFactory()
    clientConnMade = defer.Deferred()
    clientF.protocolConnectionMade = clientConnMade
    reactor.connectTCP('127.0.0.1', portNumber, clientF)
    connsMade = defer.gatherResults([serverConnMade, clientConnMade])
    def connected(result):
        (serverProtocol, clientProtocol) = result
        callback(serverProtocol, clientProtocol)
        serverProtocol.transport.loseConnection()
        clientProtocol.transport.loseConnection()
    connsMade.addCallback(connected)
    return connsMade
