Re: [twsocket] processmessages or messagepump
Arno, Arno Garrels wrote: info2004 wrote: How would I implement a timeout? Do I create a timer component within the thread, or is there a more elegant solution? A timer is ok since your thread processes messages already :-) You could, for example, use an integer that is incremented in timer's event handler and reset it to zero when TWSocket receives something. In the timer event handler check that integer. I'll look into the timer solution then. But first.Holiday. Thanks for your help. Regards, Andy -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
Francois, and Arno, while not terminated do begin WSocket.MessagePump; // check if I need to do something sleep(100); end; // close it all down Or am I missing the point in the use of the message pump? Yes, you miss something. The code you've done will be very slow at processing events because of the sleep. And it you remove the sleep, it will use all CPU. OK. The solution is simple: you need to use a real message loop. Easy: just call MessageLoop which all TWSocket instances have. To terminate the message loop, you can post a WM_QUIT message when you detect your thread has terminated. If I do: while not terminated do begin WSocket.MessageLoop; // check if I need to do something end; // close it all down Then my understanding from what you have said is that I only get to the // check if I need to do something when a quit is posted. I am running a finite state machine in the execute loop, which marshalls responses, checks timeouts etc. If I don't exit the message loop, I can't do this. Really sorry if I am missing the point on this. Long hours, fried brain. Regards, Andy -- [EMAIL PROTECTED] The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
Why don't you write your own message pump with GetMessage? This way you can process your custom messages as well. Regards, SZ On Fri, Jul 18, 2008 at 10:08 AM, info2004 [EMAIL PROTECTED] wrote: Francois, and Arno, while not terminated do begin WSocket.MessagePump; // check if I need to do something sleep(100); end; // close it all down Or am I missing the point in the use of the message pump? Yes, you miss something. The code you've done will be very slow at processing events because of the sleep. And it you remove the sleep, it will use all CPU. OK. The solution is simple: you need to use a real message loop. Easy: just call MessageLoop which all TWSocket instances have. To terminate the message loop, you can post a WM_QUIT message when you detect your thread has terminated. If I do: while not terminated do begin WSocket.MessageLoop; // check if I need to do something end; // close it all down Then my understanding from what you have said is that I only get to the // check if I need to do something when a quit is posted. I am running a finite state machine in the execute loop, which marshalls responses, checks timeouts etc. If I don't exit the message loop, I can't do this. Really sorry if I am missing the point on this. Long hours, fried brain. Regards, Andy -- [EMAIL PROTECTED] The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
Francois PIETTE wrote: So in execute is it Ok to: while not terminated do begin WSocket.MessagePump; // check if I need to do something sleep(100); end; // close it all down Or am I missing the point in the use of the message pump? Yes, you miss something. The code you've done will be very slow at processing events because of the sleep. And it you remove the sleep, it will use all CPU. You can use this to overcome sleep : // If there are messages in the queue, then do not wait at all, else, wait // as little as possible, so as to avoid 100% CPU usage and still process // as fast as we possibly can. MsgWaitForMultipleObjectsEx(0, pHandles, 1, QS_ALLINPUT, MWMO_ALERTABLE); Obviously, one has to understand message processing in the first place... -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
info2004 wrote: How would I implement a timeout? Do I create a timer component within the thread, or is there a more elegant solution? A timer is ok since your thread processes messages already :-) You could, for example, use an integer that is incremented in timer's event handler and reset it to zero when TWSocket receives something. In the timer event handler check that integer. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
Arno, So in execute is it Ok to: while not terminated do begin WSocket.MessagePump; // check if I need to do something sleep(100); end; // close it all down Or am I missing the point in the use of the message pump? Regards, Andy Arno Garrels wrote: info2004 wrote: In my thread (I know, you don't need threads...), in the execute procedure, should I call WSocket.ProcessMessages, or WSocket.MessagePump? TWSocket.ProcessMessages processes pending messages once and returns. You should call TWSocket.MessageLoop instead since it waits for and processes messages in a loop. Sending message WM_QUIT breaks the loop. Do not use TWSocket.ProcessMessages or TWSocket.MessagePump in a loop, that would slow down performance and result in high CPU use. Are they the same? If not, what is the difference? No, TWSocket.MessagePump is a method that either calls Application.ProcessMessages or TWSocket.ProcessMessages depending on define NOFORMS or your custom message pump if event OnMessagePump is assigned. BTW: All this stuff has been moved in ICS v6 to TIcsWndControl. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
So in execute is it Ok to: while not terminated do begin WSocket.MessagePump; // check if I need to do something sleep(100); end; // close it all down Or am I missing the point in the use of the message pump? Yes, you miss something. The code you've done will be very slow at processing events because of the sleep. And it you remove the sleep, it will use all CPU. The solution is simple: you need to use a real message loop. Easy: just call MessageLoop which all TWSocket instances have. To terminate the message loop, you can post a WM_QUIT message when you detect your thread has terminated. -- [EMAIL PROTECTED] The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
info2004 wrote: Arno, So in execute is it Ok to: while not terminated do begin WSocket.MessagePump; // check if I need to do something sleep(100); end; // close it all down Or am I missing the point in the use of the message pump? This is evil, don't do that, but use WSocket.MessageLoop instead, please read my previous message again. -- Arno Garrels Regards, Andy Arno Garrels wrote: info2004 wrote: In my thread (I know, you don't need threads...), in the execute procedure, should I call WSocket.ProcessMessages, or WSocket.MessagePump? TWSocket.ProcessMessages processes pending messages once and returns. You should call TWSocket.MessageLoop instead since it waits for and processes messages in a loop. Sending message WM_QUIT breaks the loop. Do not use TWSocket.ProcessMessages or TWSocket.MessagePump in a loop, that would slow down performance and result in high CPU use. Are they the same? If not, what is the difference? No, TWSocket.MessagePump is a method that either calls Application.ProcessMessages or TWSocket.ProcessMessages depending on define NOFORMS or your custom message pump if event OnMessagePump is assigned. BTW: All this stuff has been moved in ICS v6 to TIcsWndControl. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
In my thread (I know, you don't need threads...), in the execute procedure, should I call WSocket.ProcessMessages, or WSocket.MessagePump? Are they the same? If not, what is the difference? No, they are not the same. Have a look at the source code and the comments in the source code. They are very explicit and the source code is simple. Then ask more questions if needed. -- [EMAIL PROTECTED] The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
Hi again, When I got my grep correct, I found it in WSocket.pas. Looks like they are the same when multithreaded is true. ...Andy info2004 wrote: Hi, In my thread (I know, you don't need threads...), in the execute procedure, should I call WSocket.ProcessMessages, or WSocket.MessagePump? Are they the same? If not, what is the difference? Thanks, Andy -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] processmessages or messagepump
info2004 wrote: In my thread (I know, you don't need threads...), in the execute procedure, should I call WSocket.ProcessMessages, or WSocket.MessagePump? TWSocket.ProcessMessages processes pending messages once and returns. You should call TWSocket.MessageLoop instead since it waits for and processes messages in a loop. Sending message WM_QUIT breaks the loop. Do not use TWSocket.ProcessMessages or TWSocket.MessagePump in a loop, that would slow down performance and result in high CPU use. Are they the same? If not, what is the difference? No, TWSocket.MessagePump is a method that either calls Application.ProcessMessages or TWSocket.ProcessMessages depending on define NOFORMS or your custom message pump if event OnMessagePump is assigned. BTW: All this stuff has been moved in ICS v6 to TIcsWndControl. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] ProcessMessages ?
Please define local input. Using the example program ConCli1.dpr There are better console mode programs. Look at the creation date into the comments at start of source code. Generally, the more recent, the best ! ConSrv1.dpr is a good one with keyboard interaction. -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: Michael Preslar [EMAIL PROTECTED] To: ICS support mailing twsocket@elists.org Sent: Tuesday, December 20, 2005 5:07 PM Subject: [twsocket] ProcessMessages ? Hey folks.. Im working on a hobby program.. And have run into a problem. Using the example program ConCli1.dpr, I've made some modifications so that it can act as a something of a chat server. My source is available here: http://www.mpcode.com/door.zip The problem Im running into it in the TConCliApp.Run procedure. Namely, I want to do something like: while not DoneFlag do begin if keypressed then begin process local input else WSocket1.ProcessMessages; end; But it ignores local input. Any help would be appreciated. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] ProcessMessages ?
(Warning: Old School chatter among us :) ) What I'm wanting to do is write a bbs door game with a tcp client built in.. Local input (from the door) gets sent across tcp to the server, which is then relayed to all other nodes. Basically, real time interbbs. I'm the developer of Legend of the Red Dragon, Lord2, Teos, and many other door games and utilities. Interbbs exists, but its slow, and no where near real time. A client built into the door that connected to the main server (or a hub/relay server) would change things dramatically. I had originally looked at ConCli1.dpr for its simplicity, and the thought that all I had to do was check for local input before running ProcessMessages .. Judging by ConSrv1.dpr, I'll have to go about things a different way. Thanks for the heads up Francois! Francois PIETTE wrote: Please define local input. Using the example program ConCli1.dpr There are better console mode programs. Look at the creation date into the comments at start of source code. Generally, the more recent, the best ! ConSrv1.dpr is a good one with keyboard interaction. Im working on a hobby program.. And have run into a problem. Using the example program ConCli1.dpr, I've made some modifications so that it can act as a something of a chat server. My source is available here: http://www.mpcode.com/door.zip The problem Im running into it in the TConCliApp.Run procedure. Namely, I want to do something like: while not DoneFlag do begin if keypressed then begin process local input else WSocket1.ProcessMessages; end; But it ignores local input. Any help would be appreciated. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] ProcessMessages
There are two other components in the dll which suffer from the very same problem. One is the timer and another is one for the other communication method which doesn't have a processmessages. Obviously, you failed to have a working message pump. Do you have any hints for these as well? Study the IcsDll1 sample program ! -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: [EMAIL PROTECTED] To: TWSocket@elists.org Sent: Tuesday, May 03, 2005 10:22 AM Subject: [twsocket] ProcessMessages Hello, I think I must describe my problem a bit more detailed than before. I'm building a dll to encapsulate my communication routines to some extend. The dll manages all connections. When a new udp connection is to be made, a handle of my own type is allocated (I have other communication types implemented in the same dll) and the adress of a callback procedure is given. With this handle data can be sent out. The dll contains a data odlue with one TWSocket for receiving udp data. his is configured on a fixed ip/port on the local pc and if data is received, it looks in the handle list which callback is to be called (depending on the ip of the sender). The data is passed to this callback then. My test for this is an application which continously requests data from a hardware device and checks if the packets received are correct. This app. is a vcl one. If it has application.processmessages in its loop, all works as expected. But: my dll will later not be used by a vcl application but by a bunch of other dlls, so application.processmessages is not feasible. I discovered now that twsocket also has processmessages. I tried to set up a single thread in the dll which continously calls processmessages on that fixed socket (the receiving one, the sending sockets are created dynamically when a new connection gets added and get destroyed when the connection is closed [normally at the end of the program in my case]). t doesn't work. The thread is called, but data isn't received. There are two other components in the dll which suffer from the very same problem. One is the timer and another is one for the other communication method which doesn't have a processmessages. Do you have any hints for these as well? I'm stuck richt now... Greetings Markus Humm -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] ProcessMessages
- the receiving TWSocket can't be a static component on the datamodule because it has to be in a thread? Yes, the component has to be _created_ within the context of the thread that will handle his events. In case of TWSocket, you have ThreadDetach and ThreadAttach methods if it is not possible to create the component within the thread execute. But those method have a drawback; between the two, the component will not handle his events ! So it is much better to create the component directly in the correct thread context. - the sending TWSocket doen't need to be created in an thread because that sends at once (nearly) without the need of windows messages Wrong. Sending and receiving btoh use messages, even if in some cases it seems to be direct. -- [EMAIL PROTECTED] http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be