Created
January 18, 2015 06:28
-
-
Save jizhang/0cd128d97a2f8862eba3 to your computer and use it in GitHub Desktop.
simple word stream
This file contains 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
import SocketServer | |
import random | |
import time | |
words = ('cat', 'dog', 'monkey', 'horse', 'rabbit') | |
class MyTCPHandler(SocketServer.BaseRequestHandler): | |
def handle(self): | |
while True: | |
self.request.sendall(' '.join(random.sample(words, 3)) + '\n') | |
time.sleep(0.1) | |
if __name__ == '__main__': | |
server = SocketServer.TCPServer(('127.0.0.1', 9999), MyTCPHandler) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment