- import SocketServer
- import os
- import time
- 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.request is the TCP socket connected to the client
- self.data = self.request.recv(1024).strip()
- basedir = "C:\\package"
- os.chdir( basedir )
- print "%s wrote:" % self.client_address[0]
- print self.data
- if os.path.isdir(self.data)==True:
- source = self.data
- target = self.data+'.zip'
- zip_command = "C:\\\\WinRAR\\\\rar.exe a %s %s"%(target,source)
- print zip_command
- if os.system(zip_command) == 0:
- print'ok success zip'
- else:
- print'FAILED'
- # just send back the same data, but upper-cased
- self.request.send(self.data.upper())
- if __name__ == "__main__":
- HOST, PORT = "www.putclub.com", 11111
- # Create the server, binding to host on port 11111
- server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
- # Activate the server; this will keep running until you
- # interrupt the program with Ctrl-C
- server.serve_forever()
- //该片段来自于http://www.codesnippet.cn/detail/141020136405.html
来源: http://www.codesnippet.cn/detail/141020136405.html