本文整理汇总了Python中layer.Layer.send方法的典型用法代码示例。如果您正苦于以下问题:Python Layer.send方法的具体用法?Python Layer.send怎么用?Python Layer.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类layer.Layer
的用法示例。
在下文中一共展示了Layer.send方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import send [as 别名]
def run(self):
self.getMyIPMAC()
self.physicalClientSocket = socket(AF_INET, SOCK_STREAM)
self.physicalClientSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.physicalClientSocket.bind(Layer.PhysicalClient)
self.physicalClientSocket.listen(1)
while True:
self.msg.emit('Waiting datagram from Network layer')
self.package, success = Layer.receive(self.physicalClientSocket)
if success:
self.msg.emit('Received package from Network layer.')
destiny = json.loads(self.package)['destiny']
self.destiny = (destiny[0], destiny[1])
self.msg.emit ('Destiny = ' + str(self.destiny))
self.getDstMAC(self.destiny)
self.package = json.loads(self.package)['datagram']
if success:
if not self.mtuReceived:
self.connectAsClient(self.destiny)
self.createFrame_BinaryFile(self.package, 'binaryRequestClient.txt', 'blue')
if self.probCollision != 0:
while random.randint(0, 10) <= self.probCollision:
rand = random.randint(0, 10)
self.msg.emit('Collision detected, ' + str(rand) + ' seconds to retry...')
time.sleep(rand)
sent = Layer.send(self.destiny, 'binaryRequestClient.txt', self.myMTU)
self.msg.emit('Sent binary file to Physical server.')
if self.receiveFile(self.physicalClientSocket, 'binaryAnswer.txt'):
self.msg.emit('Received binary file from server')
self.answer = self.interpretPackage('binaryAnswer.txt', 'red')
sent = Layer.send(Layer.NetworkClient, self.answer)
示例2: receiveFromInternet
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import send [as 别名]
def receiveFromInternet(self):
try:
self.transportServerSocket = socket(AF_INET, SOCK_STREAM)
self.transportServerSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.transportServerSocket.bind(Layer.TransportServer)
self.transportServerSocket.listen(1)
print 'Listening...'
while True:
self.segment, success = Layer.receive(self.transportServerSocket)
self.transportProtocol = json.loads(self.segment)['transportProtocol']
self.msg.emit('Received a ' + self.transportProtocol + ' segment.')
if success:
if self.transportProtocol == 'TCP':
if not self.interpretTCPSegment(self.segment):
self.errorMsg.emit('Error trying to interpret TCP segment')
else: #UDP protocol
self.interpretUDPSegment(self.segment)
self.sendToApplication()
if self.receiveAnswer():
self.createSegment(self.transportProtocol, self.applicationPack)
sent = Layer.send(Layer.NetworkServer, self.segment)
print 'Answer sent to internet layer'
except KeyboardInterrupt:
print 'Shutting down transport server'
except Exception as exc:
exc_type, exc_obj, exc_tb = sys.exc_info()
error = exc_tb.tb_frame
line = exc_tb.tb_lineno
fileName = error.f_code.co_filename
print "Error! " + str(exc)
print 'error line = ' + str(line)
self.transportServerSocket.close()
示例3: run
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import send [as 别名]
def run(self):
#TODO change ip
self.transportClientSocket = socket(AF_INET, SOCK_STREAM)
self.transportClientSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.transportClientSocket.bind(Layer.TransportClient)
#while True:
self.transportClientSocket.listen(1)
self.msg.emit ('Listening...')
try:
while True:
if self.receiveFromApplicationLayer():
if self.transportProtocol == 'TCP':
if not self.TCPConnected :
if self.threeWayHandshake():
self.msg.emit('TCP connection established successfully'\
' through TreeWayHandshake protocol')
else:
self.errorMsg.emit ('The ThreeWayHandshake protocol could not be completed.'\
'\nVerify you connection and try again.')
break;
else:
self.sendTCPPackage()
else: #transport protocol = UDP
if self.createSegment(self.transportProtocol, self.applicationPack):
sent = Layer.send(Layer.NetworkClient, self.segment)
if self.receiveAnswer():
#TODO recognize datagram
self.sendAnswerToApplicationLayer()
except KeyboardInterrupt:
self.transportClientSocket.close()
示例4: run
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import send [as 别名]
def run(self):
self.networkServerSocket = socket(AF_INET, SOCK_STREAM)
self.networkServerSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.networkServerSocket.bind (Layer.NetworkServer)
self.networkServerSocket.listen(1)
while True:
self.package, success = Layer.receive(self.networkServerSocket)
if success:
self.interpretPackage(self.package, 'blue')
sent = Layer.send(Layer.TransportServer, self.datagram['data'])
if sent:
self.answer, success = Layer.receive(self.networkServerSocket)
self.msg.emit ('Received answer')
networkPackage = self.createNetworkPackage(Layer.PhysicalClient,self.createDatagram(self.answer, 'red'))
sent = Layer.send(Layer.PhysicalServer, networkPackage)
self.msg.emit ('Answer sent to physical layer')
示例5: run
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import send [as 别名]
def run(self):
try:
self.msg.emit('starting router')
self.physicalRouterSocket = socket(AF_INET, SOCK_STREAM)
self.physicalRouterSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.physicalRouterSocket.bind(Layer.PhysicalRouter)
self.host, self.port = Layer.PhysicalRouter
self.physicalRouterSocket.listen(1)
self.msg.emit("Setup:\nIP = " + str(self.host) + '\tPort = ' + str(self.port) + '\nListening...')
except Exception as exc:
self.errorMsg.emit('ERROR! It was not possible start the execution: \n' + str(exc))
try:
while True:
if not self.mtuSent:
self.getMyIPMAC()
self.connectAsServer(self.physicalRouterSocket)
#receive request file from client
if self.receiveFile(self.physicalRouterSocket, 'binaryRouterClientRequest.txt'):
self.package = self.interpretPackage('binaryRouterClientRequest.txt', 'blue')
#Sending to and receiving from network layer
Layer.send(Layer.NetworkRouter, self.package)
self.msg.emit('Waiting answer...')
self.answer, success = Layer.receive(self.physicalRouterSocket)
self.msg.emit('Received package from Network layer.')
serverIP = json.loads(self.answer)['destiny']
self.getDstMAC(serverIP[0])
self.answer = json.loads(self.answer)['datagram']
#Creating binary file of request from client and sending to server
self.createFrame_BinaryFile(self.answer, 'binaryRouterRequest.txt','green')
self.msg.emit ('Sending to server IP = ' + str(Layer.PhysicalServer))
self.connectAsClient(Layer.PhysicalServer)
self.msg.emit ('Request sent.');
success = Layer.send(Layer.PhysicalServer, 'binaryRouterRequest.txt', self.mtu)
#receiving answer from server
if success and self.receiveFile(self.physicalRouterSocket, 'binaryRouterServerAnswer.txt'):
self.package = self.interpretPackage('binaryRouterServerAnswer.txt', 'blue')
#sending to and receiving from network layer
Layer.send(Layer.NetworkRouter, self.package)
self.msg.emit('Waiting answer...')
self.answer, success = Layer.receive(self.physicalServerSocket)
self.msg.emit('Received package from Network layer.')
destiny = json.loads(self.answer)['destiny']
self.answer = json.loads(self.answer)['datagram']
#creating binary file of answer from server and sending to client
self.createFrame_BinaryFile(self.answer, 'binaryRouterAnswer.txt','green')
Layer.send(Layer.PhysicalClient, 'binaryRouterAnswer.txt', self.mtu)
except Exception as exc:
exc_type, exc_obj, exc_tb = sys.exc_info()
error = exc_tb.tb_frame
line = exc_tb.tb_lineno
fileName = error.f_code.co_filename
self.errorMsg.emit('ERROR! It was not possible run the server: \n' + str(exc)+
'\nLine = ' + str(line))
return False
示例6: send_SYN_ACK
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import send [as 别名]
def send_SYN_ACK(self):
self.msg.emit('Sending SYN_ACK')
tcpSegment = {'transportProtocol': 'TCP',
'srcPort': self.srcPort,
'dstPort' : self.dstPort,
'seq' : 0,
'ackSeq' : 1,
'offsetRes': 'offset',
'window': 'window',
'checksum': 'checksum',
'urgPtr': 'urgPtr',
'flags' : self.SYN_ACK,
'opcoes': 'opcoes',
'data' : 'NULL'}
self.answer = json.dumps(tcpSegment)
sent = Layer.send(Layer.NetworkServer, self.answer)
if sent:
self.msg.emit('Sent SYN_ACK to network layer.')
return True
return False