gpt4 book ai didi

Django channel 和 socket.io-client

转载 作者:行者123 更新时间:2023-12-02 03:16:55 33 4
gpt4 key购买 nike

我是第一次尝试使用它们,并且想知道我是否朝着正确的方向前进。

这是我的理解,

socket.io 是 websocket 的包装器,当 websocket 不可用时,会回退到次优解决方案。

Django channel 也可以与 websocket 通信。
(我认为它将django转换为像系统一样的消息队列。尽管这种理解或误解应该会影响这个问题)

所以我尝试在服务器上使用 Django channel ,在客户端上使用 socket.io-client。

socket.io 有一个 api,看起来像

socket.on(类型, (有效负载)=> {})

而 Django channel 的形式为

message.reply_channel.send({
“文本”:json
})

socket.on(type)的“文本”type

Django channel 和 socket.io-client 可以相互通信吗?

最佳答案

来自 Socket.IO 自述文件:

Note: Socket.IO is not a WebSocket implementation. Although Socket.IO indeed uses WebSocket as a transport when possible, it adds some metadata to each packet: the packet type, the namespace and the ack id when a message acknowledgement is needed. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a WebSocket server (like ws://echo.websocket.org) either. Please see the protocol specification here.

因此,您不应期望 Channels 直接与 Socket.IO 一起工作。 Global browser support for websockets is at 93% ,这可能足够高,只需使用 websocket API直接。

关于Django channel 和 socket.io-client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40149418/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com