-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspattern_server.py
36 lines (32 loc) · 1.4 KB
/
spattern_server.py
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
26
27
28
29
30
31
32
33
34
35
36
import socket,sys,SocketServer
from threading import Thread
class EchoRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'
self.request.send('hi ' + str(self.client_address) + '\n')
def getFile(self):
fle = self.request.makefile('r')
filename = fle.readline()
print("Got filename {}\n".format(filename))
data = 'fnord' # just something to be there for the first comparison
with open(filename[:-1], 'w') as outfile:
while data:
#data = self.request.recv(1024)
data = fle.read()
#print('writing {!r} to file ....'.format(data))
outfile.write(data)
print("Finish {}\n".format(filename))
print("finish handle")
def handle(self):
print("handle")
self.getFile()
print("finish_handle")
def finish(self):
print self.client_address, 'disconnected!'
#self.request.send('bye ' + str(self.client_address) + '\n')
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
if __name__=='__main__':
#server = SocketServer.ThreadingTCPServer(('localhost', 50000), EchoRequestHandler)
server = ThreadedTCPServer(('localhost', 50000), EchoRequestHandler)
server.serve_forever()