D
delphilxh
Unregistered / Unconfirmed
GUEST, unregistred user!
我编了个程序,使用了ics的TWSocket控件,作为服务器端,客户端也是用这个控件,但是现在有
个问题,在单机上实验没有问题,但当在服务器上运行时,时间长了,客户端就连不上服务器端了
,是什么原因造成的?
下面是服务器端的部分源码
procedure TFormmain.SrvSocketSessionAvailable(Sender: TObject; Error: Word);
var
NewClient : TWSocket;
begin
NewClient := TWSocket.Create(nil);
FClients.Add(NewClient);
NewClient.LineMode := TRUE;
NewClient.OnDataAvailable := CliSocketDataAvailable;
NewClient.LineEnd := #13#10;
NewClient.OnSessionClosed := ClientSessionClosed;
NewClient.HSocket := SrvSocket.Accept;
NewClient.LingerOnOff := wsLingerOn;
NewClient.SetLingerOption;
// Memo1.Lines.Add('建立一个连接');
end;
procedure TFormmain.ClientSessionClosed(Sender: TObject; Error: Word);
var
Cli : TWSocket;
Itm : Integer;
begin
Cli := Sender as TWSocket;
Itm := FClients.IndexOf(Cli);
if Itm >= 0 then
FClients.Delete(Itm);
PostMessage(Handle, WM_DESTROY_SOCKET, 0, LongInt(Cli));
end;
procedure TFormmain.WMDestroySocket(var msg: TMessage);
begin
TWSocket(msg.LParam).Destroy;
end;
个问题,在单机上实验没有问题,但当在服务器上运行时,时间长了,客户端就连不上服务器端了
,是什么原因造成的?
下面是服务器端的部分源码
procedure TFormmain.SrvSocketSessionAvailable(Sender: TObject; Error: Word);
var
NewClient : TWSocket;
begin
NewClient := TWSocket.Create(nil);
FClients.Add(NewClient);
NewClient.LineMode := TRUE;
NewClient.OnDataAvailable := CliSocketDataAvailable;
NewClient.LineEnd := #13#10;
NewClient.OnSessionClosed := ClientSessionClosed;
NewClient.HSocket := SrvSocket.Accept;
NewClient.LingerOnOff := wsLingerOn;
NewClient.SetLingerOption;
// Memo1.Lines.Add('建立一个连接');
end;
procedure TFormmain.ClientSessionClosed(Sender: TObject; Error: Word);
var
Cli : TWSocket;
Itm : Integer;
begin
Cli := Sender as TWSocket;
Itm := FClients.IndexOf(Cli);
if Itm >= 0 then
FClients.Delete(Itm);
PostMessage(Handle, WM_DESTROY_SOCKET, 0, LongInt(Cli));
end;
procedure TFormmain.WMDestroySocket(var msg: TMessage);
begin
TWSocket(msg.LParam).Destroy;
end;