Re: [twsocket] Two sockets in a thread

2011-03-19 Thread Francois PIETTE
I am writing a DLL that will have two sockets managed by the same thread. 
In the thread's Execute method I am calling the message pump from one of 
the sockets.


My question: will this message pump also handle the messages of the second 
socket?


For reference (and so others can check for errors), here is the thread's 
constructor, destructor and Execute method:


You should create the TWSocket inside of the Execute method instead of the 
constructor. Doing so you will avoid using ThreadAttach/detach. Use 
Try/Finally to destroy the instances.


--
francois.pie...@overbyte.be
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] Two sockets in a thread

2011-03-19 Thread AndreasGMail

Ok, thanks, will try that

On 19/03/2011 05:40, Francois PIETTE wrote:
I am writing a DLL that will have two sockets managed by the same 
thread. In the thread's Execute method I am calling the message pump 
from one of the sockets.


My question: will this message pump also handle the messages of the 
second socket?


For reference (and so others can check for errors), here is the 
thread's constructor, destructor and Execute method:


You should create the TWSocket inside of the Execute method instead of 
the constructor. Doing so you will avoid using ThreadAttach/detach. 
Use Try/Finally to destroy the instances.


--
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


[twsocket] Two sockets in a thread

2011-03-18 Thread AndreasGMail
I am writing a DLL that will have two sockets managed by the same 
thread. In the thread's Execute method I am calling the message pump 
from one of the sockets.


My question: will this message pump also handle the messages of the 
second socket?


For reference (and so others can check for errors), here is the thread's 
constructor, destructor and Execute method:


// 

constructor TTicketThrd.Create(IP: AnsiString; Handle: THandle; ID: 
integer);

begin
myIP := IP;
fHandle := Handle;
fID := ID;

TcpSocket := TWSocket.Create(Nil);
with TcpSocket do
OnDataAvailable = TcpDataAvailable;
OnSessionClosed = TcpDisconnected;
OnSessionConnected = TcpConnected;
end;

UdpSocket := TWSocket.Create(Nil);
UdpSocket.OnDataAvailable := UdpDataAvailable;

FreeOnTerminate := TRUE;
inherited Create(false);
end;

destructor TTicketThrd.Destroy;
begin
FreeAndNil(TcpSocket);
FreeAndNil(UdpSocket);
end;

procedure TTicketThrd.Execute;
begin
with TcpSocket do
begin
ThreadDetach();
MultiThreaded := true;
ThreadAttach();
end;
with UdpSocket do
begin
ThreadDetach();
MultiThreaded := true;
ThreadAttach();
end;
Sleep(0);

TcpSocket.MessageLoop();

Sleep(0);
UdpSocket.ThreadDetach;
TcpSocket.ThreadDetach;
end;


--
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] Two sockets in a thread

2011-03-18 Thread Arno Garrels
AndreasGMail wrote:
 I am writing a DLL that will have two sockets managed by the same
 thread. In the thread's Execute method I am calling the message pump
 from one of the sockets.
 
 My question: will this message pump also handle the messages of the
 second socket?

Yes it will, however your code doesn't work, you must call ThreadDetach in 
TWSocket's current thread context. Or simply create and destroy the
objects in method Execute.  

-- 

Arno Garrels

 
 For reference (and so others can check for errors), here is the
 thread's constructor, destructor and Execute method:
 
 //
 
 constructor TTicketThrd.Create(IP: AnsiString; Handle: THandle; ID:
 integer);
 begin
 myIP := IP;
 fHandle := Handle;
 fID := ID;
 
 TcpSocket := TWSocket.Create(Nil);
 with TcpSocket do
 OnDataAvailable = TcpDataAvailable;
 OnSessionClosed = TcpDisconnected;
 OnSessionConnected = TcpConnected;
 end;
 
 UdpSocket := TWSocket.Create(Nil);
 UdpSocket.OnDataAvailable := UdpDataAvailable;
 
 FreeOnTerminate := TRUE;
 inherited Create(false);
 end;
 
 destructor TTicketThrd.Destroy;
 begin
 FreeAndNil(TcpSocket);
 FreeAndNil(UdpSocket);
 end;
 
 procedure TTicketThrd.Execute;
 begin
 with TcpSocket do
 begin
 ThreadDetach();
 MultiThreaded := true;
 ThreadAttach();
 end;
 with UdpSocket do
 begin
 ThreadDetach();
 MultiThreaded := true;
 ThreadAttach();
 end;
 Sleep(0);
 
 TcpSocket.MessageLoop();
 
 Sleep(0);
 UdpSocket.ThreadDetach;
 TcpSocket.ThreadDetach;
 end;
--
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