flask nginx gevent-wesocket 实现聊天室

websocket实现聊天室

使用的工具 flask gevent-websocket nginx python3

先来一段代码`在这里插入代码片
from flask import Flask, render_template
from geventwebsocket.websocket import WebSocket, WebSocketError
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import request, redirect
from queue import Queue
from lib1 import get_key
import time
import json
import _ctypes

app = Flask(name)
user_socket_dict3 = {}
@app.route(’/ws/chat_room/’)
def ws(room_id):
if not send_msg_queue_dict.get(room_id):
send_msg_queue_dict[room_id] = Queue()
user_socket=request.environ.get(“wsgi.websocket”)
if not user_socket:
return “请以WEBSOCKET方式连接”
user_agent = request.user_agent
remote_addr = request.remote_addr
key = get_key(str(user_agent)

你可能感兴趣的:(python,flask,后端)