• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python MessageParser.MessageParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中MessageParser.MessageParser的典型用法代码示例。如果您正苦于以下问题:Python MessageParser类的具体用法?Python MessageParser怎么用?Python MessageParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: MessageReceiver

class MessageReceiver(Thread):
    """
    This is the message receiver class. The class inherits Thread, something that
    is necessary to make the MessageReceiver start a new thread, and it allows
    the chat client to both send and receive messages at the same time
    """

    def __init__(self, client, connection):
        super(MessageReceiver, self).__init__()
        """
        This method is executed when creating a new MessageReceiver object
        """

        # Flag to run thread as a deamon. A deamon is a process that runs in the background.
        self.daemon = True

        self.parser = MessageParser()
        self.client = client
        self.connection = connection
        self.start()

    def run(self):
        while True:
            received_message = self.connection.recv(4096)
            try:
                print self.parser.parse(received_message)
            except:
                pass
开发者ID:Santiario,项目名称:TTM4100,代码行数:28,代码来源:MessageReceiver.py


示例2: MessageReceiver

class MessageReceiver(Thread):
    """
    This is the message receiver class. The class inherits Thread, something that
    is necessary to make the MessageReceiver start a new thread, and it allows
    the chat client to both send and receive messages at the same time
    """

    def __init__(self, client, connection):
        """
        This method is executed when creating a new MessageReceiver object
        """

        # Flag to run thread as a deamon
        
	#self.client=client
        self.connection = connection
        # tODO: Finish initialization of MessageReceiver
        super(MessageReceiver,self).__init__()
       

    def run(self):
        # tODO: Make MessageReceiver receive and handle payloads
        self.MessageParser = MessageParser()
        #s_thread = MessageParser(payload)
        #s_thread.start()
        while True:
            payload = self.connection.recv(4096)
            #print('We now listening for input from server.' + payload)
            self.MessageParser.parse(payload)
开发者ID:madlaa,项目名称:Chat-Server-Client,代码行数:29,代码来源:MessageReceiver.py


示例3: run

    def run(self):
        # TODO: Make MessageReceiver receive and handle payloads
        parser = MessageParser()
        while True:
            self.received = self.connection.recv(1024)        # v2
            # print self.received

            print parser.parse(self.received)
开发者ID:mariusmoe,项目名称:KTN,代码行数:8,代码来源:MessageReceiver.py


示例4: __init__

class Client:
    """
    This is the chat client class
    """

    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """

        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        
        # TODO: Finish init process with necessary code
        self.host = host
        self.server_port = server_port
        
        self.messageParser = MessageParser()
        self.messageReceiver = MessageReceiver(self, self.connection)
        self.run()

    def run(self):
        """
        Main process of the client. Waits for input from user
        """
        self.connection.connect((self.host, self.server_port))

        self.messageReceiver.start()
        
        print 'Client running...\nType \'quit\' to end or \'help\' for info'
        
        while True:
            command = raw_input()
  
            if command == 'quit':
                self.disconnect()
                print 'Client closing'
                break
            
            self.send_payload(self.messageParser.parse_dataToSend(command))	
            
    def disconnect(self):
        """
		Close sock connection 
		"""
        self.connection.close()

    def receive_message(self, message):
        """
		Prints received message after it's parsed
		"""
        print self.messageParser.parse(message)

    def send_payload(self, data):
        """
		Sends data to server
		"""
        self.connection.send(data)
开发者ID:haakoneh,项目名称:TTM4100_Project,代码行数:58,代码来源:Client.py


示例5: receive_message

 def receive_message(self, message):
     #Decode message
     msg_parser = MessageParser()
     #print(message)
     #if message is None:
      #   print('oops its none')
     decoded_message = msg_parser.parse(message)
     #Print the "handled" response
     print(decoded_message)
开发者ID:shivjr,项目名称:TTM4100,代码行数:9,代码来源:Client.py


示例6: __init__

class Client:
    """
    This is the chat client class
    """

    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """
        self.serverport = server_port
        self.h = host
        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.MParser = MessageParser()
        self.MReceiver = MessageReceiver(self, self.connection)
        self.run()


    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.h, self.serverport))
        self.MReceiver.start()

        while True:
            userInput = raw_input()
            try:
                if userInput:
                    request, content = userInput.split()
                    if not content:
                        content = None
                payload = {
                    'request': request,
                    'content': content
                }
                self.send_payload(payload)

            except KeyboardInterrupt:
                self.disconnect()

    def handleInput(self, userInput):
        message = userInput.split(' ')

    def disconnect(self):
        self.connection.close()
        print "Server disconnected."


    def receive_message(self, message):
        print self.MParser.parse(message)

    def send_payload(self, data):
        payload = json.dumps(data)
        self.connection.send(payload)
开发者ID:kaisabr,项目名称:TTM4100-KTN,代码行数:53,代码来源:Client.py


示例7: __init__

class Client:
    """
    This is the chat client class
    """
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """

        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.messageParser = MessageParser()
        self.host = ""
        self.server_port = 9998
        # TODO: Finish init process with necessary code
        self.run()
        self.messageReceiver = MessageReceiver(self,self.connection)
        self.messageReceiver.start()

    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))

        
    def disconnect(self):
        self.messageReceiver.send_disconnect()
        self.connection.close()
        quit()

    def receive_message(self, message):
        self.messageParser.parse(self.printer, message)

    def printer(self,time,sender,message_type,message):
        melding = ("\n[" +
                time +" : " + message_type + "] " +
                sender+ ": " + message + "\n>>> ")
        print melding

    def send_payload(self, data):
        if data == "getHistory":
            self.messageReceiver.getHistory()
        elif data == "getNames":
            self.messageReceiver.getNames()
        elif data == "getHelp":
            self.messageReceiver.getHelp()
        else:
            self.messageReceiver.sendMessage(data)

    def login(self, data):
        brukerNavn = self.messageParser.parse_login(data)
        self.messageReceiver.send_login(brukerNavn)
开发者ID:erikebj,项目名称:KTN_prosjekt,代码行数:52,代码来源:Client.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Action.Action类代码示例发布时间:2022-05-24
下一篇:
Python Message.Message类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap