当前位置:   article > 正文

python websocket异步高并发,Python上的多线程Websocket服务器

python websocket多线程

Please help me to improve this code:

import base64

import hashlib

import threading

import socket

class WebSocketServer:

def __init__(self, host, port, limit, **kwargs):

"""

Initialize websocket server.

:param host: Host name as IP address or text definition.

:param port: Port number, which server will listen.

:param limit: Limit of connections in queue.

:param kwargs: A dict of key/value pairs. It MAY contains:

onconnect - function, called after client connected.

handshake - string, containing the handshake pattern.

magic - string, containing "magic" key, required for "handshake".

:type host: str

:type port: int

:type limit: int

:type kwargs: dict

"""

self.host = host

self.port = port

self.limit = limit

self.running = False

self.clients = []

self.args = kwargs

def start(self):

"""

Start websocket server.

"""

self.root = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

self.root.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

self.root.bind((self.host, self.port))

self.root.listen(self.limit)

self.running = True

while self.running:

client, address = self.r

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/85347
推荐阅读
相关标签
  

闽ICP备14008679号