Runner
Runner

Reputation: 6111

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.

Upvotes: 4

Views: 1553

Answers (1)

mjn
mjn

Reputation: 36654

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.

Upvotes: 3

Related Questions