Hi, Wilfried - thanks for replying :-)
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. The problem is that the DLL is quite unstable so I was trying to use a different approach and hoping to get better stability. 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. The current DLL had an issue with incoming data not being reported so I'm not sure if this is a related problem. I'll keep experimenting and hopefully I can get a working model soon :-) Regards, Adam -----Original Message----- From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On Behalf Of Wilfried Mestdagh Sent: 08 September 2011 22:42 To: 'ICS support mailing' Subject: Re: [twsocket] DLL implementation advice (or example)... Hi Adam, > Hi - after pulling out a lot of hair Hopefully you have some reserve :) > I've spent the last couple of days tinkering with the DLL 1 example > but DLL is not different from other. Only think is if you write a DLL you maybe don't know who call it. Maybe a programmer will use the DLL wich has no knowledge of message pump or the way windows work. Maybe you have to write your own message pump in that case. > Connect() needs to be passed the host, the port, the username, the If you have a working message pump then after a connection then OnSessionconnected will fire. Then you have it all. > What I need Connect() to do is kick off a worker thread that continues > running and manages the socket connection without blocking the calling > process as the current DLL example does. I'm not sure wy do you need a separate worker thread? > 2) SendStr() the username SendStr is what you can do in the OnSessionConnected event > .then sit in a loop where it: You don't need a loop! TWSocket is event driven (fortinatly) > 3) Monitors for incoming messages and adds each message to a > TStringList Every receved data you can add. Note that TCP is NOT package bound garantie. > 4) Fires off a PostMessage() to the specified window of the main > application every "pump rate" milliseconds You can give the handle to the window to the DLL from the calling application. > Connected() simply returns the connection status of the socket > GetMessage() returns information from the TStringList > Disconnect() signals the worker thread to gracefully drop the > connection (if > possible) and close down Just call the right TWSocket methods > One of the difficulties seems to be that the socket would be running > within the worker thread but the functions and data that I need to > access would be in the global scope. If you are certain you need a separate thread then you can use PostMessage (or SendMessage) -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.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