sfrazor 3 Posted October 18 (edited) First, is there specific settings when running as a DLL? What is the right way to configure the component to run as DLL? I realize this is an event driven component but I can't seem to figure out how to get the events to fire properly when not a EXE. I have a test console app(exe) and it works great doing a wss connect to the host. When building and running the DLL, after the Connect it pauses for quite some time. May be a minute or so. The onConnect event doesn't seem to fire even though the server sees the inbound connection. The Connect is in a While NOT connected. Looks something like this procedure WSComms.ConnectHost; var Retries: integer; begin Retries:= 0; WSComms.WSPingSecs := 5; WSComms.Timeou t:= 0; WSComms.ResponseNoExceptions := True; WSComms.url:= 'wss:\\192.168.1.30' While (NOT WSComms.Connected) do begin sleep(2000); WSComms.ProcessMessages; //server sees the connectoin and responds but messages/events don't fire in the DL only WSComms.Connect; WSComms.MessagePump; Inc(Retries); If Retries > 5 then Exit; end; end; procedure WSDoconnection; begin //attempt connectoin until connected WSComms.ConnectHost; While (NOT AbortFlag) do begin WSComms.ProcessMessages; end; end; So this should attempt a connection around every 2 seconds or so..... But it stays on Connect for a good minute or more and doesn't actually connect. Again, the exe version works perfectly.... So its an events issue. Edited October 18 by sfrazor update code Share this post Link to post
Angus Robertson 577 Posted October 18 Your loop is crazy, you connect, immediately test for a connection, then wait two seconds and connect again, without testing for a connection. It would be a little better if you connect before the loop. But you are using the wrong method anyway, for WebSockets it should be WSConnect and it's a blocking method, so no loop needed. Look at the doWebSocketClick function in OverbyteIcsSnippets1.pas Angus Share this post Link to post
sfrazor 3 Posted October 18 Yes, but that doesn't answer the events question. How do I get events to process in a connection loop when the events don't fire. And WSConnect is the method I'm using. That loop was off the top of my head. Meant to illustrate a connection attempt every few seconds until it was connected without timing out. I'd pull over the actual code but I work on an air-gapped network so, I can't. Share this post Link to post
sfrazor 3 Posted October 18 I updated the above code hopefully for a little more clarity. So let me ask this a different way. In the above example WSConnect reaches the Server. The Server responds. WSConnect being a blocking call just hangs. IE no Windows messaging seems to be happening. I understanding writing a message pump, but ICS has both ProcessMessages and MessgePump build in to the library. So I am attempting to use those. OverbyteIcsSnippets1.pas does not address this as it uses Application.ProcessMessages which is not available to a DLL. I have tried various ways and places to insert ProcessMessages and MessagePump as you can see above with no luck. OnWSConnected event does not not run OnWSFrameRcvd event does not run What is the proper way to use the ICS MessagePump so t hat I can properly process messages throughout the DLL? Again, the console app works perfectly. When I switch it from a console app to DLL, WSConnect blocks and never returns, because I believe Messages aren't being processed. Share this post Link to post
FPiette 385 Posted October 19 For a DLL, I recommend to put the message pump in a separate thread along will all code related to ICS events. Why? Because you have no control on what the application loading the DLL is doing with Windows messaging and because you don't know how that application calls the DLL's function (could be the main thread or a worker thread). In ICS V8, there was a sample program showing that. It has been removed from V9 😢 You still access it in this place : http://svn.overbyte.be/svn/ics/trunk/Samples/Delphi/OtherDemos The project is OverbyteIcsDll1.dpr. This project needs probably some minor changes to be compiled with V9. Share this post Link to post
Angus Robertson 577 Posted October 19 I'll restore and update the OverbyteIcsDll1.dpr sample for V9. Angus 1 Share this post Link to post
FPiette 385 Posted October 19 38 minutes ago, Angus Robertson said: I'll restore and update the OverbyteIcsDll1.dpr sample for V9. That's a good idea Angus. Restore also the sample application (OverbyteIcsDllTst1) loading the DLL. Share this post Link to post
Angus Robertson 577 Posted October 19 All the old samples archived from V9 are still available from a different SVN repository https://svn.overbyte.be/svn/icsdev/arch-samples/ I update them minimally to build for each new release. Angus 1 Share this post Link to post