title: What is supposed to be a simple TCP Client Server,, STUCK
body: <p>I am stuck. I have previously used the server and client sockets (non-indy) and they were nicely asynchronous and easy to use. I am trying to make a simple client server. Once connected to a client the server sends out small blocks of data on a timer event. The time is 77ms and the blocks of data are approximately 100 bytes.
  I have tried my best to figure out indy from bits here and there and people's examples. (Obviously there wouldn't be so much about it on the web if people could get it working quickly). Below I extracted the relevant sections from my client and server.</p>
  
  <p>I have the ip set to localhost and i am trying to first debug the server side. I start the client, I start the server in the debugger. the client connects and I can put a break point at the onconnect event and the program goes there. Now what is supposed to happen is the timer is enabled and then every time it trips I send my block of data. (this doesn't happen at least in the debugger)</p>
  
  <p>The compiler forced me to add an onexecute event for the server and I don't know what to do with it now. I tried a blank event and I tried a dummy readln.
  On the Client side. I copied a read thread from elsewhere once there is a connection it is supposed to start and read the data blocks as they occur. Right now I am not doing any error checking or automatic detection of loss of connection and attempted re-connection.</p>
  
  <p>I would certainly appreciate any help , both in getting this working and also in hints on how to handle the corner cases.</p>
  
  <p>thanks
  robert</p>
  
  <p>Server side this is supposed to send a block of data every 77 ms
  ....................................................................................</p>
  
  <pre><code>type
    TForm8 = class(TForm)
      SendButton: TButton;
      SendWaveFormTimer: TTimer;
      IdUDPClient1: TIdUDPClient;
      IdTCPServer1: TIdTCPServer;
  
      procedure SendWaveFormTimerTimer(Sender: TObject);
      procedure FormCreate(Sender: TObject);
      procedure IdTCPServer1Connect(AContext: TIdContext);
      procedure IdTCPServer1Execute(AContext: TIdContext);
  
    private
      connectedto:TIdContext;
      { Private declarations }
    public
      { Public declarations }
    end;
  
  var
    Form8: TForm8;
  
  
  procedure TForm8.IdTCPServer1Connect(AContext: TIdContext);
  // this is not in the main ui thread and can't call showmessage
  begin
    connectedto:=acontext; // save the connected TIDcontext for use elsewhere?
    self.SendWaveFormTimer.Enabled:=true; {set the send timer}
  end;
  
  procedure TForm8.SendWaveFormTimerTimer(Sender: TObject);
  
  var tempbyte:tidbytes;
  
  begin
    tempbyte:=RawToBytes(WaveFormSample,sizeof(TWaveFormSample));
    form8.connectedto.Connection.IOHandler.Write(tempbyte, sizeof(TWaveFormSample));
  end;
  
  procedure TForm8.IdTCPServer1Execute(AContext: TIdContext);
  // again this in second thread
  var recv:string;
  begin
    //I don't know what to put here I am not expecting anything right now
    recv := AContext.Connection.Socket.ReadLn;
  
  end;
  </code></pre>
  
  <p>Client Side</p>
  
  <pre><code>type
    TForm3 = class(TForm)
      IdUDPServer1: TIdUDPServer;
      Label1: TLabel;
      IdTCPClient1: TIdTCPClient;
      Button1: TButton;
      procedure IdUDPServer1UDPRead(AThread: TIdUDPListenerThread;
      const AData: TIdBytes; ABinding: TIdSocketHandle);
      procedure FormActivate(Sender: TObject);
      procedure FormCreate(Sender: TObject);
      procedure Button1Click(Sender: TObject);
    private
      { Private declarations }
    public
      { Public declarations }
    end;
  
  
  TReadingThread = class(TThread)
  protected
    FConn: TIdTCPConnection;
    procedure Execute; override;
  public
    constructor Create(ACon: TIdTCPConnection); reintroduce;
  end;
  
  type
    TMyNotify = class(TidNotify)
    private
      recvd_block:TWaveFormSample;
    protected
      procedure DoNotify; override;
    end;
  
  var
    Form3: TForm3;
    Udp_message_ID:tmessageid;
    UDp_WaveFormSample:twaveformsample;
  
    ReadingThread: TReadingThread = nil;
  
  
  implementation
  
  constructor TReadingThread.Create(ACon: TIdTCPConnection);
  begin
    FConn := ACon;
    inherited Create(False);
  end;
  
  
  
  procedure TForm3.IdTCPClient1Connected(Sender: TObject);
  begin
    readingthread.Create(IdTCPClient1);
    readingthread.execute; //this must be wrong
  end;
  
  
  procedure tform3.Button1Click(Sender: TObject);
  begin
    IdTCPClient1.Connect; //this works on the other end
  end;
  
  
  procedure TReadingThread.Execute;
  var
    TCP_TWaveFormSample:twaveformsample;
    AData: TIdBytes;
    data_rdy:boolean;
    MyNotify: TMyNotify;
  begin
    MyNotify := TMyNotify.Create;
  
    MyNotify.Notify;
    data_rdy:=false;
  
    while not Terminated do
    begin
  
      FConn.IOHandler.CheckForDataOnSource(1000);
      FConn.IOHandler.CheckForDisconnect;
      if not FConn.IOHandler.InputBufferIsEmpty and not data_rdy then
      begin
        fconn.iohandler.ReadBytes(Adata,sizeof(TWaveFormSample));
        Idglobal.BytesToRaw(AData, TCP_message_ID, sizeof(tmessageid)); //global load
        Idglobal.BytesToRaw(AData, TCP_TWaveFormSample, sizeof(twaveformsample));
        data_rdy:=true;
      end; // data
      If not Drawing and data_rdy then //make sure the other thread can take it
      begin
        MyNotify.recvd_block :=Udp_TWaveFormSample;
        MyNotify.Notify;
        data_rdy:=false;
      end;
  
    end;
  end ;
  
  procedure TMyNotify.DoNotify;
  begin
    waveformunit.writenewdata (recvd_block.WaveformIndex,recvd_block.WaveformData,
    samples_per_send);
    drawing:=false;
  end;
  </code></pre>