Example #1
0
    def sendMsg(self):

        while True:
            if(self.thrflag == 1):
                sys.exit(0)
            MsgContent = ""

            if (p2p.string_update == True):
                MsgContent = p2p.string_to_use
                p2p.string_update = False
            else:
                time.sleep(0.3)
                if(self.thrflag == 1):
                    sys.exit(0)
                continue

            MsgtoSend = Msg.Message()
            MsgtoSend.setSenderID(p2p.name)
            self.Msgcount += 1
            p2p.timestamp[p2p.UserNum - 1] += 1
            MsgtoSend.setsenderNum(p2p.UserNum)
            MsgtoSend.setTimeStamp(p2p.timestamp)
            MsgtoSend.setMsgID(self.Msgcount)
            MsgtoSend.setMsgData(MsgContent)
            finMsg = function_lib.MessagetoString(MsgtoSend)
            for connection in self.connections:
                connection.send(bytes(finMsg, 'utf-8'))
Example #2
0
    def sendMsg(self):

        while True:
            # Get Input
            MsgContent = input()
            # New message class instance
            MsgtoSend = Msg.Message()
            # Set properties for message
            MsgtoSend.setSenderID(p2p.name)
            self.Msgcount += 1
            p2p.timestamp[p2p.UserNum - 1] += 1
            MsgtoSend.setsenderNum(p2p.UserNum)
            MsgtoSend.setTimeStamp(p2p.timestamp)
            MsgtoSend.setMsgID(self.Msgcount)
            MsgtoSend.setMsgData(MsgContent)
            # Call helper function to change message to string
            finMsg = function_lib.MessagetoString(MsgtoSend)
            for i in range(len(self.socketlst)):
                if (p2p.peers[i] in self.connect_iplst):
                    self.socketlst[i].send(bytes(finMsg, 'utf-8'))