Board index » delphi » about TServerSocket , Can someone help me ?

about TServerSocket , Can someone help me ?


2004-05-20 02:07:07 PM
delphi203
hello:
i wrote some code :
TSocketListen = class(TServerSocket)
private
procedure GetThread(Sender: TObject; ClientSocket:
TServerClientWinSocket;
var SocketThread: TServerClientThread);
public
constructor Create(AOwner: TComponent); override;
end;
implementation
uses SocketThread;
{ TSocketListen }
constructor TSocketListen.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ServerType := stThreadBlocking;
OnGetThread := GetThread;
end;
procedure TSocketListen.GetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
begin
SocketThread := TSocketThread.Create(True, ClientSocket);
SocketThread.Resume ;
AList.Add(Pointer(SocketThread)); // AList is object of tList
end;
My Questions is :
1, when object of TSocketListen active:=false ,what's happen?
Can Work fine of some already Connected thread object "such as
TSocketThread(AList[i])" ?
2, when Terminate Applicaton, dose i need free Connected thread object by
self ?
thanks.
 
 

Re:about TServerSocket , Can someone help me ?

"tony" <XXXX@XXXXX.COM>writes
Quote
OnGetThread := GetThread;
You should never make a component assign event handlers to its own events.
Instead, in this case, you should be overriding the GetServerThread() or
DoCreateThread() method instead.
Quote
AList.Add(Pointer(SocketThread)); // AList is object of tList
TServerSocket already maintains a list of all the thread instances that are
created. You don't need to do it manually yourself as well.
Quote
1, when object of TSocketListen active:=false ,what's happen?
The same thing that happens when you use TServerSocket directly. You
haven't done anything yet that effects that.
Quote
Can Work fine of some already Connected thread object
"such as TSocketThread(AList[i])" ?
It is unclear what exactly you are asking. Please clearify.
Quote
2, when Terminate Applicaton, dose i need free Connected
thread object by self ?
TServerSocket owns any threads that are created. It will free them
automatically.
Gambit
 

Re:about TServerSocket , Can someone help me ?

thanks your response.
Quote
>Can Work fine of some already Connected thread object
>"such as TSocketThread(AList[i])" ?

It is unclear what exactly you are asking. Please clearify.
i means when set ServerSocket's Active to false (stop listen) , just time
if it has some Client Connections
and it is socket Connection threads will ....? disconnect or not ,or free ?
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>дÈëÓʼþ
Quote

"tony" <XXXX@XXXXX.COM>writes
news:40ac4b07$XXXX@XXXXX.COM...

>OnGetThread := GetThread;

You should never make a component assign event handlers to its own events.
Instead, in this case, you should be overriding the GetServerThread() or
DoCreateThread() method instead.

>AList.Add(Pointer(SocketThread)); // AList is object of tList

TServerSocket already maintains a list of all the thread instances that
are
created. You don't need to do it manually yourself as well.

>1, when object of TSocketListen active:=false ,what's happen?

The same thing that happens when you use TServerSocket directly. You
haven't done anything yet that effects that.

>Can Work fine of some already Connected thread object
>"such as TSocketThread(AList[i])" ?

It is unclear what exactly you are asking. Please clearify.

>2, when Terminate Applicaton, dose i need free Connected
>thread object by self ?

TServerSocket owns any threads that are created. It will free them
automatically.


Gambit


 

Re:about TServerSocket , Can someone help me ?

"tony" <XXXX@XXXXX.COM>writes
Quote
i means when set ServerSocket's Active to false (stop listen) ,
just time if it has some Client Connections and it is socket
. Connection threads will ....? disconnect or not ,or free ?
Both. If you deactivate the server, any connected clients are automatically
disconnected and the threads are freed.
Gambit
 

Re:about TServerSocket , Can someone help me ?

Quote
AList.Add(Pointer(SocketThread)); // AList is object of tList
TServerSocket already maintains a list of all the thread instances that are
created. You don't need to do it manually yourself as well.
And i want to know, how do i detect the "a list of all the thread instances
"
by tServerSocket auto maintainsed ? it seems has nothing property or method
to call.
thanks.
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>дÈëÓʼþ
Quote

"tony" <XXXX@XXXXX.COM>writes
news:40ac8424$XXXX@XXXXX.COM...

>i means when set ServerSocket's Active to false (stop listen) ,
>just time if it has some Client Connections and it is socket
. Connection threads will ....? disconnect or not ,or free ?

Both. If you deactivate the server, any connected clients are
automatically
disconnected and the threads are freed.


Gambit


 

Re:about TServerSocket , Can someone help me ?

"tony" <XXXX@XXXXX.COM>writes
Quote
And i want to know, how do i detect the "a list of all the
thread instances " by tServerSocket auto maintainsed ?
it seems has nothing property or method to call.
Use the TServerSocket.Socket.Connections[] property to access active
connections. You can use the GetClientThread() mthod to retreive the thread
pointer for any given connection. Generally, you shouldn't need to access
inactive threads at all.
Gambit