Re: Events in a console app



JamesR wrote:
I've tried using a TDataModule with a TServerSocket in a console app,
but for instance OnClientConnect never fires, although the client can
actually connect to the thread. I think it must work a differen't way
in console apps - no windows messages of course, so when I have my
console app waiting on a ReadLn() in the main program, perhaps no
events get fired.

Yep. Those events get fired in response to messages arriving at your program's window. But your program doesn't have a window, so no messages get handled.

Infact, i've also tried creating the TServerSocket in a TThread, which
again will allow a connection, but the events don't fire.

And again that's because there's nothing processing any messages.

Do I need to poll for these events. I would presume that TServerSocket
for example would have some internal notification of when the client
connects and call this event.

It does have an internal notification, but it relies on receiving a message from the OS. A message loop is fairly easy to write. The basic structure goes like this:

while GetMessage(...) > 0 do begin
TranslateMessage(...);
DispatchMessage(...);
end;

Look in MSDN for details on the parameters.

You might also consider using Indy, which does all its own listening and notification.

--
Rob
.



Relevant Pages

  • Re: mdi client problems - second try
    ... Here is what happens: Activated fires; ... This will set the form as the active MDI child and give ... A user never selects a client form. ... >> that will fit in the MDI parent. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Too many indirections?
    ... > Server instance s fires out events. ... > Client instance c must be updated according to these events. ... queue manager as a special kind of mediator. ... > that if c's interface changes then I just change m. ...
    (comp.object)
  • NIO - handling read events best practice?
    ... I have a server that waits for OP_ACCEPT and when that happens, ... When an OP_READ event is fired, my handling routine creates a "client" ... synchronized "queue". ... Now OP_READ fires again for that same client send ...
    (comp.lang.java.programmer)
  • TCP/IP Socket communication from multiple clients
    ... multiple client connections for status logging over the internet using ... simple non-Windows clients (GSM/GPRS). ... show samples as console apps and simply copy-paste doesn't work (100% CPU ...
    (microsoft.public.dotnet.languages.vb)
  • Re: window.onbeforeunload event in Netscape
    ... use the onsubmit which fires before the submit. ... This responce is very slow sometimes. ... | client should be warned. ...
    (microsoft.public.dotnet.framework.aspnet)