Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi How to wait for socket answer inside procedure?
    primarykey
    data
    text
    <p>For some specific needs i need to create procedure that waits for socket request (or answer) in dll:</p> <pre><code>TForm1 = class(TForm) ServerSocket1: TServerSocket; ...... procedure MyWaitProc; stdcall; begin Go := false; while not Go do begin // Wating... // Application.ProcessMessages; // Works with this line end; end; procedure TForm1.ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket); begin MessageBoxA(0, PAnsiChar('Received: '+Socket.ReceiveText), '', MB_OK); Go := true; end; exports MyWaitProc; </code></pre> <p>When I call <code>Application.ProcessMessages</code> everything works fine: application waits for request and then continues. But in my case calling <code>Application.ProcessMessages</code> causes to unlocking main form on host application (not dll's one). When I don't call <code>Application.ProcessMessages</code> application just hangs couse it cannot handle message...</p> <p>So, how to create such a procedure that's wating for socket answer ? Maybe there a way to wait for socket answer without using <code>Application.ProcessMessages</code> ?</p> <p>EDIT</p> <p>I also tried to use TIdTCPServer, for some reasons, the result is the same.</p> <pre><code>TForm1 = class(TForm) IdTCPServer1: TIdTCPServer; ..... procedure MyWaitProc; stdcall; begin Go := false; while not Go do begin // Waiting ... // Application.ProcessMessages; end; end; procedure TForm1.IdTCPServer1Execute(AContext: TIdContext); var s: string; begin s := AContext.Connection.Socket.ReadString(1); AllText := AllText + s; Go := True; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload