Exemple #1
0
    def __init__(self):
        self.macAddr = ""
        self.timeLimit = 1000000
        self.receiveQueue = q.Queue()
        self.transferQueue = q.Queue()
        self.lowerLayer = physicalLayer.PhysicalLayer()

        self.tr = True
        self.re = True
        trTh = thread(target=self.transferTh)
        reTh = thread(target=self.receiveTh)
        trTh.start()
        reTh.start()
Exemple #2
0
    def __init__(self, Server_Address=(socketLib.findByDomain("T2"), 80)):
        self.lowerLayer = physicalLayer.PhysicalLayer()
        self.timeLimit = 30
        myAddress = (socketLib.findByDomain("T2"), 84)
        signal.signal(signal.SIGALRM, self.alarmHandler)
        socket, AF_INET, SOCK_DGRAM, self.timeout = socketLib.socket, socketLib.AF_INET, socketLib.SOCK_DGRAM, socketLib.timeout
        self.receivedmsg = []

        self.Server_Address = Server_Address

        ##        receivingThr = thread(target=self.receiveMessage)
        ##        receivingThr.start()
        ##        lock = threading.Lock()

        with socket(AF_INET, SOCK_DGRAM) as self.sock:
            self.sock.bind(myAddress)
            self.sock.settimeout(10)  # 10 second timeout

            print(
                "UDP_Client started for UDP_Server at IP address {} on port {}"
                .format(self.Server_Address[0], self.Server_Address[1]))

            # Auto sending first message
            self.sendStrMessage("Hello Server!")
            # Recieve response
            ##            self.receiveMessage()

            while True:
                ##                try:

                time.sleep(2)
                timeout = time.time() + self.timeLimit
                while self.receivedmsg == []:  #and time.time()< timeout:
                    self.receiveMessage()
                    time.sleep(.1)
                for i in range(len(self.receivedmsg)):
                    print(self.receivedmsg[i])
                self.receivedmsg = []

                self.userInput()


##                    self.receiveMessage()
##                    print('went to recive messages')

##                except Exception as e:
##                    print('reach here')
##                    print(e)
##                    self.receiveMessage()

        print("UDP_Client ended")
Exemple #3
0
import physicalLayer
import standardSocket as socketLib

lanIP = 'T'

routerDict = {
    "E": ("192.168.100.50", 5080),
    "I": ("192.168.100.73", 5073),
    "T": ("192.168.100.84", 5084)
}

lowerLayer = physicalLayer.PhysicalLayer()

socket, AF_INET, SOCK_DGRAM, timeout = socketLib.socket, socketLib.AF_INET, socketLib.SOCK_DGRAM, socketLib.timeout

with socket(AF_INET, SOCK_DGRAM) as sock:
    sock.bind(routerDict["T"])
    print("'routing in' is now running....")

    while True:
        try:
            ret, address = sock.recvfrom(1024)
            ret = ret.decode("UTF-8")

            print("router got: " + str(ret))
            dstIP = ret[0]
            if dstIP == lanIP:
                print("sending to inside...")
                lowerLayer.transfer(ret)
        except timeout:
            print(".", end="")
Exemple #4
0
import physicalLayer

pl = physicalLayer.PhysicalLayer()

while True:
    ret = pl.receiveResistor()
    if ret != None:
        print(ret)