我正在尝试在 Rebol 中编写一个基于单个文本文件的简单聊天应用程序。
“实时”读取该文件的最佳方式是什么?
现在我已经有了它:
t1: text 600x300 wrap green black font-name font-fixed rate 1 feel[
engage: func [face action event][
if action = 'time [
face/text: read chatText
show face
]
]
]
文本字段每秒更新一次文件内容。即使有多个用户,这也有效,但是每个用户每秒都会读取整个文件。
有没有更好的方法来做这种事情?
最佳答案
看看 info?
功能。
你可以这样做:
REBOL []
chat-file: %file.txt
file-info: info? chat-file
update-date: file-info/date
view layout [
t1: text read chat-file 600x300 wrap green black font-name font-fixed rate 1 feel [
engage: func [face action event] [
if all [
action = 'time
file-info: info? chat-file
update-date < file-info/date
] [
update-date: file-info/date
face/text: read chat-file
show face
]
]
]
]
但是,如果您要从多个应用程序写入文件,则需要小心。
关于rebol - 聊天应用程序如何实时读取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37004598/