Search code examples
c#delphitcpvclindy10

Receive data from the server C# to client delphi


I want to link the tcp server programming with C# and TCPCLIENT in Delphi. How I can receive the data from the server when the client send a request for more explains in want to receive the response from the server I use every method but the data is empty.

C#

private Dictionary<string, Message> _networkStreams = new Dictionary<string, Message>();
    private void SimpleTcpClientOnDataReceived(object sender, Message e)
            {
                string Data = e.MessageString.Replace("\u0013", "");
                Request request = JsonConvert.DeserializeObject<Request>(Data);
                Message message = _networkStreams[request.RequestId];
                message.Reply(request.Data);
            }

Delphi Code

procedure TfrmList.btnsortClick(Sender: TObject);
var Request:TRequest;
  I: Integer;
  JsonArray: TJSONArray;
  ArrayElement: TJSonValue ;
  JSonValue: TJSonValue;
  item:TListItem;

begin

      Request := TRequest.Create;
      Request.Link := '/GetAll';
      Request.Password := 'Password';
      IdTCPClient1.IOHandler.Write(TJson.ObjectToJsonString(Request));
      Memo1.Text  := Memo1.Lines.Add(IdTCPClient1.IOHandler.ReadLnWait(600));

end;

Thanks.


Solution

  • you need to send (LF) or (#10) at the end of the message

    IdTCPClient1.IOHandler.Write(TJson.ObjectToJsonString(Request));
    IdTCPClient1.IOHandler.Write(#10);
    Memo1.Text  := Memo1.Lines.Add(IdTCPClient1.IOHandler.ReadLnWait(600));