简体   繁体   中英

Delphi and TIdTCPServer.OnExecute: How to correctly merge data

A very simple question I can't seem to find a definitive answer for.

I have a classic TCP Indy server. I send data in chunks. Each data packet is send in 1 or more chunks. When it arrives the OnExecute is triggered one or more times for each packet. More then one client can send data at any given time. How do I know which client / packet am I receiving data for in the OnExecute? I know its a trivial question probably but I want to have a definitive answer.

If you can design the protocol, it could be done like this:

  • the client starts with a initial command which includes total size and the chunk size
  • the server OnExecute creates a temporary output file stream and stores file information in the context
  • the client sends the chunks
  • the server OnExecute reads chunks (using Indy TCP server blocking read methods with the known chunk length) and appends them to the output stream

The Indy TCP context class can be extended to add custom information for the client connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM