- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 python socket.io 客户端,我想知道是否可以检索 session cookie,如果可以,如何获取?
另一个问题,是否可以在不通过 @sio.event
或 @sio.on()
的情况下从 .emit 获得答案? 与 websockets 库一样:
websocket.send('Hi')
response = websocket.rcv()
print(response) -> "Hi :)"
如果没有,是否可以创建一个事件/on,从服务器检索不包含事件名称的消息?
例如,我从客户端发送: sio.emit("GetNbrPlayers")
但服务器回答我 [{"data": "5"}]
没有数据之前的事件(它也是使用socket.io的服务器/api),我想收到此消息,但不可能通过事件/打开,因为答案中没有事件名称。
提前谢谢您!
最佳答案
it is possible to retrieve the session cookie,
session cookie 是什么意思?如果您指的是 Flask session cookie 之类的东西,那么不,没有 session cookie。用户 session 存储在服务器中,而不是存储在 cookie 中。
如果您指的是包含分配给客户端的 session ID 的 sid
cookie,您可以从客户端对象的 sid
属性获取此 id,例如sio.sid
。
is it possible to get the answer from an .emit without going through an @sio.event or @sio.on()?
是的,您可以使用 Socket.IO 协议(protocol)的“ack”功能来实现此目的。如果服务器是 Python 服务器,您只需从处理函数返回响应即可。例如:
@sio.event
def GetNbrPlayers():
return [{"data": "5"}]
在 Python 客户端中,您有两种方法来接收此信息。您可以使用回调函数:
def get_response(data):
print(data)
sio.emit("GetNbrPlayers", callback=get_response)
或者您可以使用 call()
而不是 emit()
将发出和回调处理合并到单个函数调用中:
data = sio.call("GetNbrPlayers")
关于python - 是否可以 : Get the cookie ? 检索没有事件名称的响应? python-socketio(客户端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56980093/
我正在选择一个 python 库来编写一个嵌入我网站的实时聊天功能页面。 我找到了两个基于 Socket.IO 的库,python-socketio 和 gevent-socketio: 来自 pyt
我正在使用 socketio 和 netty 以及 java,我对它们都是新手。 我的客户端代码如下所示。 webSocket test
我正在尝试在外部值发生变化时发送广播。 Camonitor 在值改变时调用回调,我想通知所有连接的客户端值已经改变,他们需要刷新。 from flask import Flask from epics
我在使用 flasks socketio 时遇到了问题,似乎当我调用 socketio.emit('my event', 'my message') 时它根本不会发出任何事件。 .. 所以这是我的设置
我有一个 socketio 服务器/客户端可以很好地协同工作,但是我想开始为服务器在页面加载或正常运行期间脱机时编写事件。 我在我的头文件中包含了远程 socket.io 代码: /socket.io
我正在使用 flask-socketio 和 python-socketio 开发一个项目。为了确保通信安全,系统需要使用 SSL 进行升级。我正在使用 Mac 和 Python 3.7。 我使用 o
我目前正在尝试了解套接字的工作原理。我正在使用 Flask-socketio 和 python socketio 客户端并运行一个基本示例。这是我到目前为止所做的 应用.py from flask i
我正在尝试使用 Socket.IO 开发一个聊天应用程序。我的服务器端是安装了 express + socket.io 库的 Node.js,我的客户端是 Android + Web。 我尝试在我的客
我正在构建一个 Android 聊天应用程序。我在服务器端使用 nodejs 并尝试实现 android client for socketIO.我收到 SocketIO 异常。代码有什么问题? 服务
我将 Flask 与 gevent-socketio 一起使用: $ cat requirements.txt Flask==0.10.1 Jinja2==2.7.1 MarkupSafe==0.18
我正在为某个项目使用 netty-socketio。我像这样设置了一个服务器: Configuration config = new Configuration(); config.setHostna
所以,我需要收集很多数据,比如每秒 3 个单位的数据,由很多人收集。我将收集此数据的事件命名为“捕获”。 我正在使用 JWT 对其他数据密集度较低的事件进行身份验证。 现在,我只是担心使用每个数据密集
socketio不仅可以用来做聊天工具,也可以实现局域网(当然你如果有外网也可用外网)内实现文件的上传和下载,下面是代码的效果演示: git地址: https://github.com/fen
我正在使用 flask-socketio 创建一个聊天应用程序,现在我想在客户端断开连接时使用客户端的用户名向服务器发送一条消息,即当客户端关闭浏览器/选项卡时,以便我可以将该消息从服务器发送到所有现
我正在尝试向从单独文件连接的所有套接字发出。但是我似乎无法弄清楚。 Socket.js var socketio = require('socket.io'); var users = require
我尝试在我的 django 应用程序中实现与 django-socketio 的聊天。 首先要了解django-socketio,所以看了https://github.com/stephenmcd/d
我对网络编程有点陌生。我现在正在尝试编写一个服务器。在服务器端我有一个方法: socket.on("joinserver", function(name, device) { }); 在客户端,
我正在尝试将数据从客户端发送到服务器端。我只得到未定义。我希望用户单击 ledOn 函数来发送 1 ,并单击 ledOff 来发送 0 到服务器。 server.js io.sockets.on('c
我使用nodejs设置了一个简单的Socket服务器gameIo gameIo.on("connection", socket => { socket.on("sign up", () => {
我想知道是否有一种方法可以在两个(或多个)flask-socketio 服务器之间直接通信。我想在服务器之间传递信息,并让客户端连接单个 Web 套接字服务器,该服务器将具有来自其他服务器的所有组合逻
我是一名优秀的程序员,十分优秀!