Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How read file real time for chat application?

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?

like image 204
lechuck Avatar asked Oct 31 '22 04:10

lechuck


1 Answers

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.

like image 180
endo64 Avatar answered Nov 04 '22 09:11

endo64