龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php socket连接python进行文件打包

时间:2014-09-06 15:17来源:网络整理 作者:网络 点击:
分享到:
php socket连接python进行文件打包 [代码片段(42行)]
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://outofmemory.cn
精彩图集

赞助商链接