I'm getting a stream with JSON strings and I'm displaying it in a TMemo. It happens that I am not able to process JSON correctly because it does not always come with the same amount of characters from the server. You would need to process the JSONs and display the results in another TMemo. I've heard of buffering, streams etc but I'm not familiar with them.
Note: Use TClientSocket
procedure TForm1.csClienteRead(Sender: TObject; Socket: TCustomWinSocket);
var
data: String;
begin
data := Socket.ReceiveText;
memoResults.Lines.Add(data);
end;
As soon as I connect the Client connection, I receive this data:
{ "age" : "0", "camera" : "0", "direction" : "===", "id" : "12", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328838" }
{ "age" : "0", "camera" : "0", "direction" : "===", "id" : "11", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328838" }
{ "age" : "1", "camera" : "0", "direction" : "===", "id" : "10", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328837" }
{ "age" : "1", "camera" : "0", "direction" : "===", "id" : "9", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328837" }
{ "age" : "2", "camera" : "0", "direction" : "===", "id" : "8", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328836" }
{ "age" : "2", "camera" : "0", "direction" : "===", "id" : "7", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328836" }
{ "age" : "3", "camera" : "0", "direction" : "===", "id" : "6", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328835" }
{ "age" : "3", "camera" : "0", "direction" : "===", "id" : "5", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328835" }
{ "age" : "4", "camera" : "0", "direction" : "===", "id" : "4", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328834" }
{ "age" : "4", "camera" : "0", "direction" : "===", "id" : "3", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328834" }
{ "age" : "16402735", "camera" : "0", "direction" : ">>>", "id" : "0", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926103" }
{ "age" : "16402735", "camera" : "0", "direction" : "===", "id" : "2", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926103" }
{ "age" : "16402736", "camera" : "0", "direction" : "===", "id" : "1", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926102" }
{ "age" : "16402736", "camera" : "0", "direction" : "===", "id" : "0", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926102" }
After this begins to come line by line but sometimes it all comes together without line breaks. I need 1 JSON at a time otherwise the system does not process.