I'm trying to write a simple chat application in Rebol which is based on a single text file. What would be the best way to read that file "real time"? Right now I've got it working with this:
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
]
]
]
The text field gets updated every second with the content of the file. That works, even with multiple users, but the whole file is read every second for every user. Is there a better way to do this kind of thing?
Have a look on info?
function.
You can do something like this:
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
]
]
]
]
But you need to be careful if you will write to the file from multiple apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With