本文整理汇总了Python中connection.Connection.terminate方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.terminate方法的具体用法?Python Connection.terminate怎么用?Python Connection.terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.terminate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ClientApplication
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import terminate [as 别名]
class ClientApplication(object):
'''
Used for testing the methods that will be available via the RTP-3251 API
'''
def __init__(self):
pass
#Client commands
def connect(self, portOfClient=12000, destIp="143.215.129.100", destPort=7000):
#Command: connect (only for projects that support bi-directional transfers)
#The FTA-client connects to the FTA-server (running at the same IP host).
self.clientConnection = Connection()
self.clientConnection.open(portOfClient, (destIp, destPort))
def getF(self, fileName):
#Command: get F (only for projects that support bi-directional transfers)
#The FTA-client downloads file F from the server (if F exists in the same directory as the fta-server executable).
fileRequestObj = ['FFFFFFFF', fileName]
self.clientConnection.send(pickle.dumps(fileRequestObj))
serialObj = None
while(serialObj == None):
serialObj = self.clientConnection.receive()
fullfilledRequest = pickle.loads(serialObj)
if (fullfilledRequest[0] == fileName+"FromServer"): #write the contents (i.e. the second item in the object array
f = open(fileName+"FromServer", "w")
# file_path = path.relpath("clientFiles/"+fileName)
f.write(fullfilledRequest[1])
f.close()
print ("Client successfully received", fileName+"FromServer")
else:
print ("Client received", fullfilledRequest[0], "but was expecting", fileName+"FromServer")
def postF(self, fileName):
#Command: post F (only for projects that support bi-directional transfers)
#The FTA-client uploads file F to the server (if F exists in the same directory as the fta-client executable).
f = open(fileName, 'r')
obj = [fileName+"AtServer", f.read()]
f.close()
self.clientConnection.send(pickle.dumps(obj))
serialObj = None
while(serialObj == None):
serialObj = self.clientConnection.receive()
serverReply = pickle.loads(serialObj)
if (serverReply[0] == fileName+"AtServer" and serverReply[1] == "confirmed"):
print (fileName + " was confirmed")
else:
print (fileName + " was not confirmed!")
def terminate(self):
#Command: disconnect (only for projects that support bi-directional transfers)
#The FTA-client terminates gracefully from the FTA-server.
self.clientConnection.terminate()
示例2: ServerApplication
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import terminate [as 别名]
class ServerApplication():
'''
Used for testing the methods that will be available via the RTP-3251 API
'''
def __init__(self, _debug=False):
self._debug = _debug
pass
def openServer(self, portOfServer=12001):
self.serverConnection = Connection(self._debug)
self.serverConnection.open(portOfServer)
def listen(self):
while(1):
serialObj = None
while(serialObj == None):
serialObj = self.serverConnection.receive() #stuck until receives a file read or write request
requestObj = pickle.loads(serialObj)
if (requestObj[0] == "FFFFFFFF"): #client wants file
self.replyF(requestObj[1])
else: #client is posting file as ['filename', content]
f = open(requestObj[0],'w')
f.write(requestObj[1])
f.close()
fileConfirmation = [requestObj[0], 'confirmed']
self.serverConnection.send(pickle.dumps(fileConfirmation))
def replyF(self, fileName):
#Command: post F (only for projects that support bi-directional transfers)
#The FTA-client uploads file F to the server (if F exists in the same directory as the fta-client executable).
f = open(fileName, 'r')
obj = [fileName+"FromServer", f.read()]
f.close()
self.serverConnection.send(pickle.dumps(obj))
def terminate(self):
#Shuts down FTA-Server gracefully
self.serverConnection.terminate()
示例3: client
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import terminate [as 别名]
def client():
clientConn = Connection()
clientConn.open(12000, ('127.0.0.1',12001))
t = time.clock()
while (time.clock() - t < 2): pass
clientConn.terminate()