Created
April 6, 2016 21:29
-
-
Save abhigenie92/03c2d5d92a93b138cb2b143e50d306b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet.protocol import DatagramProtocol | |
# Here's a UDP version of the simplest possible protocol | |
class AudioEchoUDP(DatagramProtocol): | |
echoers = [] | |
def startProtocol(self): | |
print "Audio server started" | |
def datagramReceived(self, datagram, address): | |
if address not in self.echoers: | |
self.echoers.append(address) | |
for echoer in self.echoers: | |
if echoer!=address: | |
self.transport.write(datagram, address) | |
def connectionRefused(self): | |
pass | |
def main(): | |
from twisted.internet import reactor | |
port = reactor.listenUDP(0, AudioEchoUDP()) | |
audio_port=port.getHost().port | |
print audio_port | |
reactor.run() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment