Search code examples
delphiindydelphi-xe7delphi-xe8

Sending data from TIdTCPClient to TServerSocket in FMX is not working for Delphi XE8


I'm using Delphi XE8 trail version for developing application mobile application. Currently I'm facing very critical problem below I have explained clearly.

My Project is divided into two different applications:

Application A: This application is developed using Delphi XE8 as VCL application. This application has the TServerSocket. And receives the data using array of bytes. Mostly, this application receives the data as packed record and based on the Message Header the next step will be taken place.

Application B: This application is developed using Delphi XE8 as Multi Device mobile application. This application has TIdTCPClient. And sends the data as mentioned below:

TSamplePacket = packed record
  strValue: array [0..10] of Char;
end;

Procedure SendData;
var
  SamplePacket: TSamplePacket;
begin
  SamplePacket.strValue := '1000';
  IdTCPClient1.IOHandler.Write(@SamplePacket, SizeOf(TSamplePacket));
end;

And for IdTCPClient, IOHandler is assigned .

Problem: When I called SendData procedure in Delphi XE8 Multidevice mobile application it have not received any data in server app and also no exception is raised in client. And I have checked in Windows 7 desktop and also Android mobile Lolipop version mobile. In both device, the client application is not sending the data. And same code worked finely in Delphi XE7 for Windows application and Android KitKat version mobile application. And In Delphi XE8 Multi Device mobile application, I have tried to convert the packed record to TIDBytes. But I don't know how to do this.?

But when I have created Delphi XC8 VCL Application and implemented the same code and the same components and I tried to send the data, it receiving data in the Server application.

And in Delphi XE8 Multidevice mobile application, if I tried to send the text which is shown below:

IdTCPClient1.IOHandler.Writeln('test');

And when I used this I can able to receive the data in Server application.

Please provide me any help to send this buffer data to server socket properly. And Thanks in advance


Solution

  • Application A: This application is developed using Delphi XE8 as VCL application. This application has the TServerSocket.

    TServerSocket has been deprecated for years, and is no longer installed by default. It is provided only for backwards compatibility with old code. Since you are using Indy anyway, you should consider using TIdTCPServer instead.

    IdTCPClient1.IOHandler.Write(@SamplePacket, SizeOf(TSamplePacket));

    There is no overloaded version of TIdIOHandler.Write() that accepts such parameter values. You need to send the data as a TIdBytes:

    Procedure SendData;
    var
      SamplePacket: TSamplePacket;
    begin
      SamplePacket.strValue := '1000';
      IdTCPClient1.IOHandler.Write(RawToBytes(SamplePacket, SizeOf(TSamplePacket)));
    end;
    

    Or as a TStream:

    Procedure SendData;
    var
      SamplePacket: TSamplePacket;
      Strm: TIdMemoryBufferStream;
    begin
      SamplePacket.strValue := '1000';
      Strm: TIdMemoryBufferStream.Create(@SamplePacket, SizeOf(TSamplePacket));
      try
        IdTCPClient1.IOHandler.Write(Strm);
      finally
        Strm.Free;
      end;
    end;