2016-05-03 43 views
5

我正试图在基于单个文本文件的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 
     ] 
    ] 
] 

文本字段被更新每一秒与文件的内容。即使对于多个用户也是如此,但每个用户每秒都会读取整个文件。 有没有更好的方法来做这种事情?

+1

为什么不在读它之前检查文件是否被修改? –

回答

2

看看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 
      ] 
     ] 
    ] 
] 

但是你必须小心,如果你会写从多个应用程序的文件。