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


Python Layer.receive方法代码示例

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


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

示例1: run

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [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
开发者ID:thaisdb,项目名称:TCC,代码行数:62,代码来源:physicalLayerServer.py

示例2: receiveFromInternet

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [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()
开发者ID:thaisdb,项目名称:TCC,代码行数:34,代码来源:transportLayerServer.py

示例3: run

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [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)
开发者ID:thaisdb,项目名称:TCC,代码行数:34,代码来源:physicalLayerClient.py

示例4: run

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [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')
开发者ID:thaisdb,项目名称:TCC,代码行数:18,代码来源:networkLayer.py

示例5: threeWayHandshake

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [as 别名]
 def threeWayHandshake(self):
     if self.receive(self.SYN):
         if self.send_SYN_ACK():
             self.segment, success = Layer.receive(self.transportServerSocket)
             self.segment = json.loads(self.segment)
             if self.receive(self.ACK):
                 self.msg.emit('Three way handshake protocol established connection!')
                 #self.receive_Data()
                 return True
     return False
开发者ID:thaisdb,项目名称:TCC,代码行数:12,代码来源:transportLayerServer.py

示例6: receiveAnswer

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [as 别名]
 def receiveAnswer(self):
     self.answer, success = Layer.receive(self.transportClientSocket)
     if success:
         self.msg.emit('Received answer from Network layer.')
         if self.transportProtocol == 'UDP':
             self.interpretUDPSegment(self.answer)
         else:
             self.interpretTCPSegment(self.answer)
     print 'received answer' + str(success)
     #self.answer = json.loads(self.answer)
     return success
开发者ID:thaisdb,项目名称:TCC,代码行数:13,代码来源:transportLayerClient.py

示例7: receive_SYN_ACK

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [as 别名]
 def receive_SYN_ACK (self):
     try:
         self.answer, success = Layer.receive(self.transportClientSocket)
         if success:
             self.msg.emit('Checking SYN_ACK')
             self.answer = json.loads(self.answer)
             self.html.emit(PDUPrinter.TCP(self.answer, 'blue'))
             if self.answer['flags'] == self.SYN_ACK:
                 return True
             else:
                 self.msg.emit('Acknowledge sequence number doesn\'t check')
                 return False
     except Exception as exc:
         self.errorMsg.emit('DID NOT Receive SYN_ACK\n' + str(exc))
         return False
开发者ID:thaisdb,项目名称:TCC,代码行数:17,代码来源:transportLayerClient.py

示例8: receiveFile

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import receive [as 别名]
 def receiveFile(self, socket, fileName):
     with open (fileName, "w") as self.rFile:
         data, success = Layer.receive(socket)
         self.rFile.write(data)
     self.msg.emit('Received frame')
     return success
开发者ID:thaisdb,项目名称:TCC,代码行数:8,代码来源:physicalLayerClient.py


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