当前位置: 首页>>代码示例>>Python>>正文


Python Package.getPackage方法代码示例

本文整理汇总了Python中package.Package.getPackage方法的典型用法代码示例。如果您正苦于以下问题:Python Package.getPackage方法的具体用法?Python Package.getPackage怎么用?Python Package.getPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在package.Package的用法示例。


在下文中一共展示了Package.getPackage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: up

# 需要导入模块: from package import Package [as 别名]
# 或者: from package.Package import getPackage [as 别名]
    def up(self):
        while True:
            conn, addr = self.sock.accept()
            print 'Connection address:', addr
            while 1:
                data = conn.recv(BUFFER_SIZE)
                if not data: break
                package = Package(11, 320)
                package.setPackage(data)
                package.decode()


                if package.type == 0 or package.type == 1:
                    reply_package = Package(1)
                    messages_data = self.call(package)
                    reply_package.data = ''.join(messages_data)
                    if DEVELOP: print package.__str__()
                    conn.send(reply_package.getPackage())  # echo
                elif package.type == 2:
                    reply_package = Package(2)
                    reply_package.data = 'OK'
                    if DEVELOP: print package.__str__()
                    conn.send(reply_package.getPackage())

                if package.command.name == 'send_file':
                    var = package.command.variables.split()
                    filename = var[0]
                    mode = var[1]

                    print "Start receiving"
                    file = open(filename, mode)
                    file.write(package.data.decode())
                    file.close()

            conn.close()
开发者ID:zhekan,项目名称:MDrun3,代码行数:37,代码来源:tcpserver.py

示例2: send

# 需要导入模块: from package import Package [as 别名]
# 或者: from package.Package import getPackage [as 别名]
    def send(self):
        package = Package()
        package.type = self._type_package
        package.user = self._user
        package.command = self._command
        PACKAGE = package.getPackage()

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((TCP_IP, TCP_PORT))
        s.send(PACKAGE)
        data = s.recv(BUFFER_SIZE)
        s.close()

        package = Package()
        package.setPackage(data)

        if package.type == 0:
            pass

        if package.type == 1:
            message = str(package.data)
            #message = message.split('$$NEWLINE$$ $$NEWLINE$$')
            #message = '\n'.join(message)
            #message = message.replace('$$NEWLINE$$','',1)
            print message
        if package.type == 2:
            print "Status: {}".format(package.data)
        if package.type == 3:
            print "Data sending"
开发者ID:zhekan,项目名称:MDrun3,代码行数:31,代码来源:tcpclient.py

示例3: sendFile

# 需要导入模块: from package import Package [as 别名]
# 或者: from package.Package import getPackage [as 别名]
    def sendFile(self, filename):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((TCP_IP, TCP_PORT))
        package = Package(3)
        package.command.variables = ' '.join([filename, 'wb'])

        print "Starting sending file"
        with open(filename,'rb') as file:
            print 'Sending..'
            data = file.read(2048)

            package.command.name = 'send_file'
            package.data = data.encode()
            s.send(package.getPackage())
            package.command.variables = '{} {}'.format(filename, 'a')
开发者ID:zhekan,项目名称:MDrun3,代码行数:17,代码来源:tcpclient.py


注:本文中的package.Package.getPackage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。