'Test that a datagram can be sent to and received by a server and vice
versa.'

def test_exchange(self):

    clientaddr = self.mktemp()
    serveraddr = self.mktemp()
    sp = ServerProto()
    cp = ClientProto()
    s = reactor.listenUNIXDatagram(serveraddr, sp)
    self.addCleanup(s.stopListening)
    c = reactor.connectUNIXDatagram(serveraddr, cp, bindAddress=clientaddr)
    self.addCleanup(c.stopListening)
    d = defer.gatherResults([sp.deferredStarted, cp.deferredStarted])
    def write(ignored):
        cp.transport.write('hi')
        return defer.gatherResults([sp.deferredGotWhat, cp.deferredGotBack])
    def _cbTestExchange(ignored):
        self.assertEqual('hi', sp.gotwhat)
        self.assertEqual(clientaddr, sp.gotfrom)
        self.assertEqual('hi    back', cp.gotback)
    d.addCallback(write)
    d.addCallback(_cbTestExchange)
    return d
