-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
25 lines (20 loc) · 789 Bytes
/
server.py
File metadata and controls
25 lines (20 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/python
import SocketServer
import phrasen
g=phrasen.generator("words.txt")
class MyTCPHandler(SocketServer.BaseRequestHandler):
"""
The RequestHandler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
client.
"""
def handle(self):
self.data = self.request.recv(1024).strip()
phrase=("<meta http-equiv='content-type' content='text/html; charset=UTF-8'>Ich fordere: Wer %s, der %s!" % (g.generateWordPair())).encode('utf8', 'replace')
self.request.sendall(phrase)
print phrase
if __name__ == "__main__":
HOST, PORT = "localhost", 8080
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()