![](/img/trans.png)
[英]Send data from Python to node a server with socket (NodeJS,Socket.io)
[英]Send data from python script to socket.io server
我有以下問題:
我的機器上運行着一個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 });
蟒蛇:
def my_callback2(channel):
fout=open("../sio/position.txt","w")
fout.write("P1")
fout.close()
print "falling edge detected on 18"
在此解決方案中,我看到事件(寫入文件)與服務器的響應之間存在很高的延遲。
現在,我認為應該有一種方法可以將信息從python腳本直接傳遞到服務器/客戶端(我想在網頁上查看更改)。
嚴有人請幫我嗎?
揚尼克
已經有一個用於Python的socket.io 1.0客戶端 。
如果由於某種原因這對您都不起作用,則始終可以在兩個進程之間建立簡單的TCP連接(或使用UNIX套接字),然后將換行符分隔的JSON從Python傳輸到節點,然后將其發送到連接套接字.io客戶以某種形式出現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.