Re: [twsocket] DLL implementation advice (or example)...
Hi Adam, > The problem is that the DLL is quite unstable so I was trying to use a > different approach and hoping to get better stability. Are we talking about TWSocket in your second approach? > Right now, I have the basic DLL test project running - it is connecting > to > my server but the worker thread is not terminating so either the server > is > not sending a response or the ondatareceived event is not triggering. I'm not sure if a TDatamodule is thread safe. Anyway I never used it. Note that what you create in a constructor is in main thread context. You have to create (and destroy) the components in the Execute method of that thread. If you do not then you have a false thread. -- mvg, Wilfried -- 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] DLL implementation advice (or example)...
Adam, you should read my recent message called "ICS in DLL. My report about results" here in mail list. I faced with tons of troubles because of DLL nature so finally I returned to my own blocking socket classes (just a simple WinSock wrapper - fortunately I needed only basic functions in DLL). For client library it works flawlessly. For server and complicated client apps I continue using ICS. -- Anton -- 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] DLL implementation advice (or example)...
>I have an existing DLL that was written to use TClientSocket via a data >module. It has a kind of message pump but it works in reverse... it has a >timer thread that uses postmessage to trigger the main app to call a >ReadData function which checks the socket for received data, then processes it. It's a really overcomplicated one! I'd recommend you to isolate main app objects/variables from DLL ones as strongly as possible. For example: * Main app calls DLL's Connect() with a pointer to callback method. * DLL's Connect() saves this pointer, allocates buffer for data and connects to the host specified * In OnDataAvailable DLL copies data to buffer and calls the callback with parameters (PBufStart: PByte; PDataLen: Integer). * Callback copies data to application's buffer thread-safely (you'll have to use additional thread for socket messages otherwise you'll get funny side effect when DLL's Socket.MessageLoop processes main app's messages) and signals main app thread to process the data received. Callback should return number of bytes it has read so that DLL could move a pointer to data start in the buffer. In general, only simple and cross-language types should be used when interacting with DLL. This means NO CLASSES in parameters/results! -- Anton -- 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] DLL implementation advice (or example)...
> I'm not a beginner with Delphi but I'm definitely not an expert > either so I'm really struggling to create a DLL-based WSocket > client that does what I need. I wrote an ActiveX DLL about 10 years ago that's still used on my web site today, doing a reverse DNS look-up on the remote IP address that is then displayed on the web page. It uses normal async ICS components, with a message loop to process the messages. It is designed with a timeout, so it does not delay the page been displayed too long if there is not DNS response, but it's easy to change the main message loop to run until a 'disconnect' flag is set. The ResultList variable is set in the OnDnsLookupDone event. I have an array of sockets so multiple requests can be handled. // start lookup ResultList [mysocket] := '' ; WSockets [mysocket].ReverseDnsLookup (IPAddr) ; // now wait for lookup to complete or timeout after X seconds if (Timeout = 0) or (Timeout > 10) then Timeout := LookupTimeout ; WaitTickList [mysocket] := GetTickCount + LongWord (Timeout * 1000) ; while ResultList [mysocket] = '' do begin if GetTickCount >= WaitTickList [mysocket] then begin try WSockets [mysocket].Abort ; except end ; ResultList [mysocket] := '(Lookup Timed Out)' ; end ; WSockets [mysocket].ProcessMessages ; Sleep (0) ; end ; Angus -- 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