DelphiBuilder / NetCom7

The fastest communications possible. Delphi rulez.
MIT License
174 stars 43 forks source link

Messages sent from server timeout with RequiresResult=false and Async=True #5

Closed MauricDaniel closed 4 years ago

MauricDaniel commented 4 years ago

The intention is for server to "broadcast" changes received from one client to all other connected clients with least amount of latency. Testing Client/Server Sources demos so that Server pushes changes reveals an issue with messages time out when RequiresResult=false and AsyncExecute=True

Reproducible by applying following changes to ncServerSourceHandleCommand:

function TForm1.ncServerSourceHandleCommand(Sender: TObject;
  aLine: TncSourceLine; aCmd: Integer; aData: TArray<System.Byte>;
  aRequiresResult: Boolean; const aSenderComponent,
  aReceiverComponent: string): TArray<System.Byte>;
var
  Line: TncSourceLine;
  Sockets: TSocketHandleList;
  i: integer;
begin
  // Comment out the following line if you want to test the server's real response speed
  Memo1.Lines.Add('Given response for data: ' + StringOf (aData));
  Result := aData;
  Sockets := ncServerSource.Lines.LockList;
  try
  for i := 0 to Sockets.Count - 1 do
  begin
    Line := Sockets.Objects[i] as TncSourceLine;
    if Line <> aLine then
      ncServerSource.ExecCommand(Line,0, BytesOf('Test'+IntToStr(i)), false, true);
  end;
  finally
    ncServerSource.Lines.UnlockList;
  end;

Run server with code above and also run at least two clients. Send message from one client and other clients should receive it. While it sometimes works, it raises a TimeOut more often than not. With RequiresResult to True it works correctly. Also with RequiresResult=false and AsyncExecute=false it works correctly.

Is RequiresResult=false and AsyncExecute=True unsupported, or is it a bug ?

DelphiBuilder commented 4 years ago

Dear Daniel,

I have seen the problem and I'm on it. Please bare with me a few days because this modification is a serious one. Thank you so very much for finding this out.

DelphiBuilder commented 4 years ago

Daniel hi again man!

You will find the new code is now excellent. It has been re-engineered. Hope you like it. Enjoy :)