Python将原始响应发送到套接字

Python将原始响应发送到套接字,python,websocket,bottle,Python,Websocket,Bottle,我已经使用gevent websocket有一段时间了,但由于某种原因,它在OSX和linux上都神秘地崩溃了。bitbucket和pypi上的人拒绝了我的请求,没有做出回应,stackoverflow上的人也是如此。我正计划编写自己的WebSocket实现,但我需要访问原始连接对象(如socket模块中的socket对象),该对象管理原始数据的发送和接收。我在哪能找到这个?我正在寻找可能如下所示的代码: @route("/websocket") def ws(): raw_conn =

我已经使用gevent websocket有一段时间了,但由于某种原因,它在OSX和linux上都神秘地崩溃了。bitbucket和pypi上的人拒绝了我的请求,没有做出回应,stackoverflow上的人也是如此。我正计划编写自己的WebSocket实现,但我需要访问原始连接对象(如socket模块中的socket对象),该对象管理原始数据的发送和接收。我在哪能找到这个?我正在寻找可能如下所示的代码:

@route("/websocket")
def ws():
    raw_conn = ??? # socket object from socket module
    # initialize websocket here, following protocols and then send messages
    while True:
        raw_conn.send(raw_conn.recv()) # Simple echo

我为此编写的一些代码非常有用:

import abc
import socket


class Communication(metaclass=abc.ABCMeta):
    def __init__(self, port):
        self.port = port
        self.connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def send_message(self, message):
        self.my_connexion.send(message.encode())

    def wait_for_message(self, nb_characters = 1024):
        message = self.my_connexion.recv(nb_characters)          
        return message.decode()

    def close_connexion(self):
        self.connexion.close()


class Client(Communication):
    def __init__(self, port):
        Communication.__init__(self, port)     
        self.connexion.connect(("localhost", port))
        self.my_connexion = self.connexion

class Server(Communication):
    def __init__(self, port, failed_connexion_attempt_max = 1):
        Communication.__init__(self, port)

        self.connexion.bind(("", port))
        self.connexion.listen(failed_connexion_attempt_max)
        self.my_connexion, address = self.connexion.accept()

    def close_connexion(self):
        self.client_connexion.close()
        self.connexion.close()

我为此编写的一些代码非常有用:

import abc
import socket


class Communication(metaclass=abc.ABCMeta):
    def __init__(self, port):
        self.port = port
        self.connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def send_message(self, message):
        self.my_connexion.send(message.encode())

    def wait_for_message(self, nb_characters = 1024):
        message = self.my_connexion.recv(nb_characters)          
        return message.decode()

    def close_connexion(self):
        self.connexion.close()


class Client(Communication):
    def __init__(self, port):
        Communication.__init__(self, port)     
        self.connexion.connect(("localhost", port))
        self.my_connexion = self.connexion

class Server(Communication):
    def __init__(self, port, failed_connexion_attempt_max = 1):
        Communication.__init__(self, port)

        self.connexion.bind(("", port))
        self.connexion.listen(failed_connexion_attempt_max)
        self.my_connexion, address = self.connexion.accept()

    def close_connexion(self):
        self.client_connexion.close()
        self.connexion.close()

这对瓶装水没用。这对瓶装水没用。你介意链接到你发布的关于
gevent websocket
如何损坏的SO问题吗?我很想知道细节。谢谢您是否介意链接到您发布的关于
gevent websocket
如何损坏的SO问题?我很想知道细节。谢谢