1.「Hack.Chat」安全匿名在线聊天室
2.å¦ä½ç¨Pythonç¼åä¸ä¸ªè天室
3.聊天室实现流程
「Hack.Chat」安全匿名在线聊天室
匿名免注册的聊天在线聊天工具「Hack.Chat」基于Node.js编写,实时聊天,室源不保存任何聊天信息,码聊提供安全的天室黑色主题界面。
创建新聊天室只需在网址后加上“?房间名”,源码如:hack.chat/?聊天jeesite源码分析...
登录房间后,弹窗提示输入昵称,室源界面显示在线用户和消息发送人昵称及其颜色区分,码聊新用户提示系统通知。天室
注意,源码加入者无法查看未加入前的聊天聊天内容。聊天室兼容移动终端,室源访问速度快,码聊源码哪里最多消息即时传递。天室聊天室有效期随消息记录刷新而消失,源码昵称需重新设定。
「Hack.Chat」是一款开源聊天系统,任何人都可利用服务器搭建。官网及GitHub地址如下:hack.chat、视讯qp源码github.com/AndrewBelt/h...
注意,作者已停止更新此项目,已开发另一个版本:github.com/hack-chat/m...
「Hack.Chat」有类似在线匿名聊天工具如tlk.io。创建聊天室无需任何广告,可嵌入自定义网站。
两个开源项目,亨利源码详情请自行查看:github.com/zhangfu-git/...、github.com/chatwoot/chat...
文章原创,禁止转载。
软件探索专注于推荐实用软件与网站,如果您喜欢,欢迎关注。疫苗预约源码
å¦ä½ç¨Pythonç¼åä¸ä¸ªè天室
ä¸ã课ç¨ä»ç»1.ç®ä»
æ¬æ¬¡é¡¹ç®è¯¾æ¯å®ç°ç®åè天室ç¨åºçæå¡å¨ç«¯å客æ·ç«¯ã
2.ç¥è¯ç¹
æå¡å¨ç«¯æ¶åå°asyncoreãasynchatåsocketè¿å 个模åï¼å®¢æ·ç«¯ç¨å°äºtelnetlibãwxãtimeåthreadè¿å 个模åã
3.æéç¯å¢
æ¬æ¬¡è¯¾ä¸ç¼å客æ·ç«¯éè¦ç¨å°wxPythonï¼å®æ¯ä¸ä¸ªGUIå·¥å ·å ï¼è¯·å 使ç¨ä¸é¢çå½ä»¤å®è£ ï¼
$ sudo apt-get install python-wxtools
å¯ç 为shiyanlou
4.项ç®æææªå¾
ç»å½çªå£
è天çªå£
äºã项ç®å®æï¼æå¡å¨ç«¯ï¼
1.æå¡å¨ç±»
é¦å éè¦ä¸ä¸ªè天æå¡å¨ï¼è¿é继æ¿asyncoreçdispatcherç±»æ¥å®ç°ï¼ä»£ç å¦ä¸
class ChatServer(dispatcher):
"""
è天æå¡å¨
"""
def __init__(self, port):
dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind(('', port))
self.listen(5)
self.users = { }
self.main_room = ChatRoom(self)
def handle_accept(self):
conn, addr = self.accept()
ChatSession(self, conn)
2.ä¼è¯ç±»
æäºæå¡å¨ç±»è¿éè¦è½ç»´æ¤æ¯ä¸ªç¨æ·çè¿æ¥ä¼è¯ï¼è¿é继æ¿asynchatçasync_chatç±»æ¥å®ç°ï¼ä»£ç å¦ä¸ï¼
class ChatSession(async_chat):
"""
è´è´£ååç¨æ·éä¿¡
"""
def __init__(self, server, sock):
async_chat.__init__(self, sock)
self.server = server
self.set_terminator('\n')
self.data = []
self.name = None
self.enter(LoginRoom(server))
def enter(self, room):
'ä»å½åæ¿é´ç§»é¤èªèº«ï¼ç¶åæ·»å å°æå®æ¿é´'
try:
cur = self.room
except AttributeError:
pass
else:
cur.remove(self)
self.room = room
room.add(self)
def collect_incoming_data(self, data):
'æ¥å客æ·ç«¯çæ°æ®'
self.data.append(data)
def found_terminator(self):
'å½å®¢æ·ç«¯çä¸æ¡æ°æ®ç»ææ¶çå¤ç'
line = ''.join(self.data)
self.data = []
try:
self.room.handle(self, line)
except EndSession:
self.handle_close()
def handle_close(self):
async_chat.handle_close(self)
self.enter(LogoutRoom(self.server))
3.å½ä»¤è§£éå¨
ç°å¨å°±éè¦ä¸ä¸ªå½ä»¤è§£éå¨è½å¤è§£éç¨æ·çå½ä»¤ï¼ä¾å¦ç»å½ãæ¥è¯¢å¨çº¿ç¨æ·ååæ¶æ¯çï¼ä»£ç å¦ä¸ï¼
class CommandHandler:
"""
å½ä»¤å¤çç±»
"""
def unknown(self, session, cmd):
'ååºæªç¥å½ä»¤'
session.push('Unknown command: %s\n' % cmd)
def handle(self, session, line):
'å½ä»¤å¤ç'
if not line.strip():
return
parts = line.split(' ', 1)
cmd = parts[0]
try:
line = parts[1].strip()
except IndexError:
line = ''
meth = getattr(self, 'do_' + cmd, None)
try:
meth(session, line)
except TypeError:
self.unknown(session, cmd)
4.æ¿é´
æ¥ä¸æ¥å°±éè¦å®ç°è天室çæ¿é´äºï¼è¿éæ们å®ä¹äºä¸ç§æ¿é´ï¼åå«æ¯ç¨æ·åç»å½æ¶çæ¿é´ãè天çæ¿é´åéåºç»å½çæ¿é´ï¼è¿ä¸ç§æ¿é´é½æä¸ä¸ªå ¬å ±çç¶ç±»ï¼ä»£ç å¦ä¸ï¼
class Room(CommandHandler):
"""
å å«å¤ä¸ªç¨æ·çç¯å¢ï¼è´è´£åºæ¬çå½ä»¤å¤çå广æ
"""
def __init__(self, server):
self.server = server
self.sessions = []
def add(self, session):
'ä¸ä¸ªç¨æ·è¿å ¥æ¿é´'
self.sessions.append(session)
def remove(self, session):
'ä¸ä¸ªç¨æ·ç¦»å¼æ¿é´'
self.sessions.remove(session)
def broadcast(self, line):
'åææçç¨æ·åéæå®æ¶æ¯'
for session in self.sessions:
session.push(line)
def do_logout(self, session, line):
'éåºæ¿é´'
raise EndSession
class LoginRoom(Room):
"""
åç»å½çç¨æ·çæ¿é´
"""
def add(self, session):
'ç¨æ·è¿æ¥æåçååº'
Room.add(self, session)
session.push('Connect Success')
def do_login(self, session, line):
'ç»å½å½ä»¤å¤ç'
name = line.strip()
if not name:
session.push('UserName Empty')
elif name in self.server.users:
session.push('UserName Exist')
else:
session.name = name
session.enter(self.server.main_room)
class ChatRoom(Room):
"""
è天ç¨çæ¿é´
"""
def add(self, session):
'广ææ°ç¨æ·è¿å ¥'
session.push('Login Success')
self.broadcast(session.name + ' has entered the room.\n')
self.server.users[session.name] = session
Room.add(self, session)
def remove(self, session):
'广æç¨æ·ç¦»å¼'
Room.remove(self, session)
self.broadcast(session.name + ' has left the room.\n')
def do_say(self, session, line):
'客æ·ç«¯åéæ¶æ¯'
self.broadcast(session.name + ': ' + line + '\n')
def do_look(self, session, line):
'æ¥çå¨çº¿ç¨æ·'
session.push('Online Users:\n')
for other in self.sessions:
session.push(other.name + '\n')
class LogoutRoom(Room):
"""
ç¨æ·éåºæ¶çæ¿é´
"""
def add(self, session):
'ä»æå¡å¨ä¸ç§»é¤'
try:
del self.server.users[session.name]
except KeyError:
pass
5.æå¡å¨ç«¯å®æ´ä»£ç
#!/usr/bin/python
# encoding: utf-8
from asyncore import dispatcher
from asynchat import async_chat
import socket, asyncore
PORT = #端å£
class EndSession(Exception):
"""
èªå®ä¹ä¼è¯ç»ææ¶çå¼å¸¸
"""
pass
class CommandHandler:
"""
å½ä»¤å¤çç±»
"""
def unknown(self, session, cmd):
'ååºæªç¥å½ä»¤'
session.push('Unknown command: %s\n' % cmd)
def handle(self, session, line):
'å½ä»¤å¤ç'
if not line.strip():
return
parts = line.split(' ', 1)
cmd = parts[0]
try:
line = parts[1].strip()
except IndexError:
line = ''
meth = getattr(self, 'do_' + cmd, None)
try:
meth(session, line)
except TypeError:
self.unknown(session, cmd)
class Room(CommandHandler):
"""
å å«å¤ä¸ªç¨æ·çç¯å¢ï¼è´è´£åºæ¬çå½ä»¤å¤çå广æ
"""
def __init__(self, server):
self.server = server
self.sessions = []
def add(self, session):
'ä¸ä¸ªç¨æ·è¿å ¥æ¿é´'
self.sessions.append(session)
def remove(self, session):
'ä¸ä¸ªç¨æ·ç¦»å¼æ¿é´'
self.sessions.remove(session)
def broadcast(self, line):
'åææçç¨æ·åéæå®æ¶æ¯'
for session in self.sessions:
session.push(line)
def do_logout(self, session, line):
'éåºæ¿é´'
raise EndSession
class LoginRoom(Room):
"""
åç»å½çç¨æ·çæ¿é´
"""
def add(self, session):
'ç¨æ·è¿æ¥æåçååº'
Room.add(self, session)
session.push('Connect Success')
def do_login(self, session, line):
'ç»å½å½ä»¤å¤ç'
name = line.strip()
if not name:
session.push('UserName Empty')
elif name in self.server.users:
session.push('UserName Exist')
else:
session.name = name
session.enter(self.server.main_room)
class ChatRoom(Room):
"""
è天ç¨çæ¿é´
"""
def add(self, session):
'广ææ°ç¨æ·è¿å ¥'
session.push('Login Success')
self.broadcast(session.name + ' has entered the room.\n')
self.server.users[session.name] = session
Room.add(self, session)
def remove(self, session):
'广æç¨æ·ç¦»å¼'
Room.remove(self, session)
self.broadcast(session.name + ' has left the room.\n')
def do_say(self, session, line):
'客æ·ç«¯åéæ¶æ¯'
self.broadcast(session.name + ': ' + line + '\n')
def do_look(self, session, line):
'æ¥çå¨çº¿ç¨æ·'
session.push('Online Users:\n')
for other in self.sessions:
session.push(other.name + '\n')
class LogoutRoom(Room):
"""
ç¨æ·éåºæ¶çæ¿é´
"""
def add(self, session):
'ä»æå¡å¨ä¸ç§»é¤'
try:
del self.server.users[session.name]
except KeyError:
pass
class ChatSession(async_chat):
"""
è´è´£ååç¨æ·éä¿¡
"""
def __init__(self, server, sock):
async_chat.__init__(self, sock)
self.server = server
self.set_terminator('\n')
self.data = []
self.name = None
self.enter(LoginRoom(server))
def enter(self, room):
'ä»å½åæ¿é´ç§»é¤èªèº«ï¼ç¶åæ·»å å°æå®æ¿é´'
try:
cur = self.room
except AttributeError:
pass
else:
cur.remove(self)
self.room = room
room.add(self)
def collect_incoming_data(self, data):
'æ¥å客æ·ç«¯çæ°æ®'
self.data.append(data)
def found_terminator(self):
'å½å®¢æ·ç«¯çä¸æ¡æ°æ®ç»ææ¶çå¤ç'
line = ''.join(self.data)
self.data = []
try:
self.room.handle(self, line)
except EndSession:
self.handle_close()
def handle_close(self):
async_chat.handle_close(self)
self.enter(LogoutRoom(self.server))
class ChatServer(dispatcher):
"""
è天æå¡å¨
"""
def __init__(self, port):
dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind(('', port))
self.listen(5)
self.users = { }
self.main_room = ChatRoom(self)
def handle_accept(self):
conn, addr = self.accept()
ChatSession(self, conn)
if __name__ == '__main__':
s = ChatServer(PORT)
try:
asyncore.loop()
except KeyboardInterrupt:
ä¸ã项ç®å®æï¼å®¢æ·ç«¯ï¼
å®æäºæå¡å¨ç«¯åï¼å°±éè¦å®ç°å®¢æ·ç«¯äºï¼è¿é客æ·ç«¯è¿æ¥æå¡å¨ä½¿ç¨äºtelnetlib模åã
1.ç»å½çªå£
è¿éçå¾å½¢çé¢å éæ©äºwxPythonï¼åé¢æå®è£ 说æï¼ç»å½çªå£éè¿ç»§æ¿wx.Frameç±»æ¥å®ç°ï¼ä»£ç å¦ä¸ï¼
class LoginFrame(wx.Frame):
"""
ç»å½çªå£
聊天室实现流程
聊天室的实现流程主要分为服务器端和客户端两部分。1. 服务器端实现流程
用户的数据通过URL进行传输,下面是一些示例,这些示例有助于我们理解整个系统的架构。例如,当用户使用用户名'aaa'和经过crypt加密的密码登录,说出'hello'后,会触发一系列请求。具体如下:URL: /login?username=aaa&password=encrypted('aaa') (登录请求)
URL: /chat?message=hello (发送消息请求)
URL: /logout (退出登录请求)
密码在传输过程中已加密,确保了安全性。2. 客户端登录流程
客户端界面设计分为三个部分:聊天内容显示部分(chat帧):主要显示用户之间的对话内容。
输入和管理功能区域(talk帧):用户在此输入文字、执行动作,如发送消息、过滤信息以及管理其他功能,如设置或更改个人信息。
在线用户列表(names帧):实时更新显示当前在线的用户名单,通过定时刷新保持最新状态。
扩展资料
聊天室(chat room)是一个网上空间,为了保证谈话的焦点,聊天室通常有一定的谈话主题。任何一个联入Internet、使用正确的聊天软件,并且渴望谈论的人都可以享受其乐趣。聊天室有语音聊天室和视频聊天室等分类。2024-12-24 09:23
2024-12-24 08:28
2024-12-24 08:26
2024-12-24 08:13
2024-12-24 07:42
2024-12-24 07:13