I have the following problem:
I hava a python script and a socket.io server running on my machine. Now, I want to pass Data fom the python script to the Server and the client. At the moment, I am using the following:
Server:
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"
In this solution, I see a very high latency between the event (writing file) and the reaction of my server.
Now, I thought there should be a way to directly pass information from the python script to the server/client (I want to see the change on the webpage).
Yan anybody please help me?
Yannic
There is already a socket.io 1.0 client for Python .
If that doesn't work for you for whatever reason, you could always just establish a plain TCP connection (or use a UNIX socket) between the two processes and transfer newline-delimited JSON from Python to node, which then gets emitted to connection socket.io clients in some form or another.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.