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


Python UI.append方法代码示例

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


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

示例1: Client

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import append [as 别名]
class Client(object):
    def __init__(self):
        # self.records = []
        self.host = "0.0.0.0"
        self.port = 3657
        self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # self.stdin = sys.stdin
        # self.local_socket_server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        # self.local_socket_client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        # self.sockets = [self.stdin, self.client_socket]
        # self.sockets = [self.local_socket_server, self.client_socket]
        self.interrupt_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        try:
            os.remove('client_termin_io.sock')
        except OSError:
            pass
        self.s_termin_io = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.c_termin_io = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s_termin_io.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.c_termin_io.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.sockets = [self.client_socket]
        self.sockets.append(self.s_termin_io)
        self.is_started = False
        self.io_port = 3659

    def run(self):
        #if not self.is_started:
        #self.start()
        self._loop()

    def start(self):
        self.s_termin_io.bind(('localhost', self.io_port))
        self.s_termin_io.listen(1)
        self.client_socket.connect(("localhost", self.port))
        self.interrupt_socket.bind('client_interrupt.sock')
        self.interrupt_socket.listen(1)
        self.ui = UI(self.c_termin_io, self.io_port, True) 
        client_run = self.run
        ui_run = self.ui.run
        threading.Thread(target=ui_run).start()
        client_run()

    def end(self):
        self.client_socket.close()
        try:
            os.remove('client_interrupt.sock')
        except OSError:
            pass
        #self.ui.end()

    def _loop(self):
        logging.info("in loop")
        try:
            while True:
                rsockets,wsockets,esockets = select.select(self.sockets,[],[])
                for _socket in rsockets:
                    # receive msg
                    if _socket == self.client_socket:
                        data = _socket.recv(4096)
                        if data:
                            # self.records.append(data)
                            logging.info(data)
                            self.ui.append(data)
                        else:
                            logging.error("\nDisconnect from server")
                            sys.exit()
                    elif _socket == self.interrupt_socket:
                        continue
                    elif _socket == self.s_termin_io:
                        try:
                            logging.info("client s_termin_io target")
                            sockfd, addr = _socket.accept()
                            self.io = sockfd
                            self.sockets.append(self.io)
                            data = self.io.recv(4096)
                            if data:
                                self.client_socket.send(data)
                        except:
                            self.io.close()
                            logging.info("socket err, einfo {}".format(einfo()))
                    elif _socket == self.io:
                        data = self.io.recv(4096)
                        logging.info("client io send {}".format(data))
                        if data:
                            self.client_socket.send(data)
                    else:
                        data = _socket.recv(4096)
                        if data:
                            logging.info("data: {}".format(data))

                    # send msg
                    # elif _socket == self.local_socket_server:
                    #     msg = _socket.recv(4096)
                    #     self.client_socket.send(msg)
                    # else:
                        # msg = sys.stdin.readline()
                        # self.client_socket.send(msg)
                        # send message to server
                    #    msg = _socket.recv(4096)
                    #    self.client_socket.send(msg)
#.........这里部分代码省略.........
开发者ID:SeavantUUz,项目名称:silence,代码行数:103,代码来源:chat_client.py


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