zmqchat.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:zmq-chat 作者: jnthnwn 项目源码 文件源码
def main(stdscr):
    config_file = args.config_file if args.config_file is not None else 'zmqchat.cfg'
    config = configparser.ConfigParser()
    config.read(config_file)
    config = config['default']

    receiver = zmq.Context().instance().socket(zmq.PAIR)
    receiver.bind("inproc://clientchat")
    sender = zmq.Context().instance().socket(zmq.PAIR)
    sender.connect("inproc://clientchat")
    client = ClientChat(args.username, config['server_host'],
                        config['chat_port'], receiver)
    client.run()

    display_receiver = zmq.Context().instance().socket(zmq.PAIR)
    display_receiver.bind("inproc://clientdisplay")
    display_sender = zmq.Context().instance().socket(zmq.PAIR)
    display_sender.connect("inproc://clientdisplay")
    display = ClientDisplay(config['server_host'], config['display_port'], display_sender)
    display.run()

    ### curses set up
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
    # ensure that user input is echoed to the screen
    curses.echo()
    curses.curs_set(0)

    window_height = curses.LINES
    window_width = curses.COLS
    division_line =  int(window_height * 0.8)

    # instaniate two pads - one for displaying received messages
    # and one for showing the message the user is about to send off
    top_pad = stdscr.subpad(division_line, window_width, 0, 0)
    bottom_pad = stdscr.subpad(window_height - division_line, window_width, division_line, 0)

    top_thread = threading.Thread(target=start_top_window, args=(top_pad, display_receiver))
    top_thread.daemon = True
    top_thread.start()

    bottom_thread = threading.Thread(target=start_bottom_window, args=(bottom_pad, sender))
    bottom_thread.daemon = True
    bottom_thread.start()

    top_thread.join()
    bottom_thread.join()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号