django 基于dwebsocket发送二进制ws 的方法

修改源码

路径:

/home/你的用户名/.local/lib/python版本号/site-packages/dwebsocket/backends/default/websocket.py

在其原来的代码中中,源代码是这样的:

def send(self, message):
    '''
    Send a message to the client. message should be convertable to a
    string; unicode objects should be encodable as utf-8.
    '''
    if not self.closed:
        self.protocol.write(message)

修改后的:

def send(self, message, binary=False):
    '''
    Send a message to the client. message should be convertable to a
    string; unicode objects should be encodable as utf-8.
    '''
    if not self.closed:
        self.protocol.write(message, binary)

使用方法

调用的时候记得采用为request.websocket.send(data,True),比原版的输入参数多个True。
可以传送二进制数据。而js接收的时候用arraybuffer接收

posted @ 2021-11-29 17:16  res2677  阅读(161)  评论(0)    收藏  举报