Delphi 2007, Indy 10 - What is the simplest TCP/IP setup for transferring a block of data in one direction -
i have application (the "server") updates block of data in memory - around 100k bytes - every second.
there 1 4 other instances of "client" application running on other workstations on same network, , these need read same 100k image every second.
this has been implemented til writing image file on server , having clients read file across network. has worked no problems many years, lately (coincident move windows 8-based hardware) has developed problem file becomes inaccessible nodes except one. exiting client application running on node frees file , becomes accessible again everyone.
i'm still perplexed the cause of lockout, i'm wondering if may mechanism discussed here, file isn't closed due network glitch. i'm thinking having clients request data on tcp/ip avoid this.
there doesn't need handshaking other clients failing connect or read data - server needs go it's business , respond requests grabbing data , sending it. i'm pretty hazy best architecture achieve this. tidtcpclient , tidtcpserver going cut it? i'm assuming clients request data in thread, mean server needs run thread continuously respond requests?
tidtcpserver
multi-threaded component. clients run in worker threads manages you. have implement onexecute
event send data.
tidtcpclient
not multi-threaded component. runs in whatever thread use in. if need read data continuously, best run own worker thread handle reading. indy has tidthreadcomponent
component wraps thread, or can write own tthread
code manually.
100k not lot of data, suggest forgetting file altogether , allocate buffer in memory instead. tidtcpserver.onexecute
event handler can read buffer whenever needed. , wouldn't bother having clients request data, have server continuously push latest data active clients.
try this:
server:
var buffer: tidbytes; lock: tmrewsync; procedure tform1.idtcpserver1execute(acontext: tidcontext); begin lock.beginread; try acontext.connection.iohandler.write(buffer); lock.endread; end; sleep(1000); end; procedure tform1.updatebuffer; begin lock.beginwrite; try // update buffer content needed... lock.endwrite; end; end; initialization lock := tmrewsync.create; setlength(buffer, 1024 * 100); finalization setlength(buffer, 0); lock.free;
client:
procedure tform1.idthreadcomponent1run(sender: tidthreadcomponent); var buffer: tidbytes; begin idtcpclient1.iohandler.readbytes(buffer, 1024 * 100); // use buffer needed... end; procedure tform1.connect; begin idtcpclient1.connect; try idthreadcomponent1.start; except idtcpclient1.disconnect; raise; end; end; procedure tform1.disconnect; begin idtcpclient1.disconnect; idthreadcomponent1.stop; end;
Comments
Post a Comment