Skip to content Skip to main navigation Skip to footer

python基于进程内通讯的聊天室实现方法

python基于进程内通讯的聊天室是如何来实现的呢?下面的内容将会通过具体的实例来演示python基于进程内通讯的聊天室的实现方法及相关技巧:

本文实例讲述了基于进程内通讯的python聊天室实现方法。分享给大家供大家参考。具体如下:

#!/usr/bin/env python
# Added by <ctang@redhat.com>
import sys
import os
from multiprocessing import connection
ADDR = ('', 9997)
AUTH_KEY = '12345'
class Server(object):
  def __init__(self, username):
    self.auth_key = AUTH_KEY
    self.addr = ADDR
    self.username = username
    self.listener = connection.Listener(self.addr, authkey=self.auth_key)
  def listen(self):
    while True:
      conn = self.listener.accept()
      while True:
        try:
          request = conn.recv()
          response = self.response(request)
          conn.send(response)
        except EOFError:
          break
   

python基于进程内通讯的聊天室就是这样,欢迎大家参考。。。。

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.