【问题标题】:Send data from python script to socket.io server将数据从 python 脚本发送到 socket.io 服务器
【发布时间】:2015-08-28 15:23:00
【问题描述】:

我有以下问题:

我有一个 python 脚本和一个在我的机器上运行的 socket.io 服务器。 现在,我想将 python 脚本中的数据传递给服务器和客户端。 目前,我正在使用以下内容:

服务器:

  fs.watchFile('position.txt', function (curr, prev) {
    //console.log('the current mtime is: ' + curr.mtime);
    //console.log('the previous mtime was: ' + prev.mtime);
    io.emit('positionswechsel', curr.mtime); //need the content of the file here
  });

Python:

def my_callback2(channel):
    fout=open("../sio/position.txt","w")
    fout.write("P1")
    fout.close()
print "falling edge detected on 18"

在这个解决方案中,我发现事件(写入文件)和服务器的反应之间的延迟非常高。

现在,我认为应该有一种方法可以将信息从 python 脚本直接传递到服务器/客户端(我想在网页上看到更改)。

有人请帮帮我吗?

亚尼克

【问题讨论】:

    标签: python node.js socket.io


    【解决方案1】:

    已经有一个socket.io 1.0 client for Python

    如果由于某种原因这对您不起作用,您总是可以在两个进程之间建立一个普通的 TCP 连接(或使用 UNIX 套接字)并将换行符分隔的 JSON 从 Python 传输到节点,然后发出以某种形式连接 socket.io 客户端。

    【讨论】:

    • 您好,谢谢。不幸的是,我无法安装客户端。有人可以帮忙吗?
    猜你喜欢
    • 2021-01-26
    • 2012-12-31
    • 2021-03-20
    • 1970-01-01
    • 2018-11-19
    • 2016-12-15
    • 1970-01-01
    • 2013-01-03
    • 2017-02-16
    相关资源
    最近更新 更多