Delphi - write / read files in a shared environment

I have some problems with files that are located on the local network: there is one Delphi program (server), which should write some files that can only be read by a few Deplhi programs (clients). I use these simple instructions on the server to write (DataList is TStrings):

Stream:=TFileStream.Create(filePath,fmOpenWrite or fmShareDenyWrite);
try
 DataList.SaveToStream(Stream);
finally
 Stream.Free;
end;

The client checks every 5 seconds if the file above changes (just checking the FileAge), and if changes occur, they load the DataList as follows:

try
 Stream:=TFileStream.Create(filePath,fmOpenRead or fmShareDenyNone);
 DataList.LoadFromStream(Stream);
finally
 Stream.Free;
end;

Usually everything works fine, but sometimes it happens that the server or client throws an exception because "the file is being used by another process." I don’t understand what the problem is: I tried many alternatives, but this can happen with the server, and only with one of the client’s clients.

?

!

+5
1

. , NFS ( Linux) SMB ( Windows) : .

Client-Server. TCP/IP, HTTP .

, DataSnap, RemObjects Open Source mORMot.

+3

All Articles