本文整理汇总了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()
示例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"
示例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')