Hello!
I have a client application that should connect to different servers at the
same time but for each connection it may have very lengthy operations so I
decided to used one thread per connection, but I´m writting this email just to
be sure that I´m doing the right thing
Basically I have a thread class that have an internal socket component:
TDriverCommSocketThread = class(TDigiThread)
private
// Connection socket
FSocket: TWSocket;
and this is my execute method
TDriverCommSocketThread.Execute;
begin
// Creates the socket
FSocket := TWSocket.Create(nil);
FSocket.MultiThreaded := TRUE;
FSocket.OnSessionConnected := HandleOnSocketConnected;
FSocket.OnSessionClosed := HandleOnSocketClosed;
FSocket.OnDataAvailable := HandleOnSocketDataAvailable;
FSocket.OnError := HandleOnSocketError;
FSocket.OnBgException := HandleOnSocketException;
FSocket.Connect;
// Message Loop
while GetMessage(MsgRec, 0, 0, 0) do
begin
if not Terminated then
begin
// Process the received messages
TranslateMessage(MsgRec);
DispatchMessage(MsgRec)
end;
end;
end;
Doing this, all events like OnSessionConnected, OnSessionClosed,
OnDataAvailable, OnError and OnBgException will be triggered within my message
loop, consequently it will be triggered on the thread´s context right?
Do I need to do any other things to make it work right? Now it is working
great, but I´m having some problems that I don´t know if it is related to this
multi-threaded scenario, because of that I´m asking if I´m doing the right
thing..
Another thing, now FSocket is being destroyed on my class destructor, should I
destroy it on the end of the execute method, after leaving the message loop?
Thanks a lot!
Éric Fleming Bonilha
--
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