Search code examples
delphiindy

Sending and receiving data streams in Delphi


I want to create a software to connect to another and send some data (text based) to another program through the internet.

The software will send data every 300 milliseconds (using timer) and the receiver must receive the data on time.

The connection can be like the following

  1. any data can be lost;
  2. but the rest must arrive on time with minimum delay as possible (maximum 2 seconds);
  3. the delayed data can be considers as lost, can be ignored.

I think it may be similar to a video conference software, but only using simple text as data.

Can anyone tell me how to make such a program, specifically

  • what kind of component can I use (any INDY examples);
  • what technologies do you recommend.

I have planned to do it with Delphi but other recommendation also welcome .

==========================update1 =================

Is it possible to send images through the stream


Solution

  • I suggest using UDP protocol and adding timestamp information to your data and track incoming data on the receiving end. You can use UDP server (TIdUDPServer) and client (TIdUDPClient) components from Indy or other packages. Client component is for sending data and server for receiving.

    Personally I usually prefer Synapse -classes. They are lower level than Indy, so it's easier to know what's happening but on the otherhand you may need to implement something yourself what Indy may provide by default.

    Update

    Implementation is pretty straight forward:

    Sending data:

    Drop TIdUDPClient on the form. Set "Host" to name or IP address of receiving end (or "localhost" if you run your programs in same computer) and port to high number where server is listening, eg 54656.

    Add following code to button or timer event:

    IdUDPClient1.Send('Hello, world!');
    

    Receiving data:

    Drop TIdUDPServer component on the form. Set default port to same port as in sending application. Add OnUDPRead event handler, with code:

    MessageDlg('Received: ' + StringOf(AData), mtInformation, [mbOk], 0);
    

    And new message dialog pops up everytime new message is received.

    Update 2

    UDP is not good for images, if you want to be sure they will stay uncorrupted, unless the image is very small and fits inside one packet.