keepalivetime: cardinal; // 多長時間(ms)沒有資料就開始send心跳包
keepaliveinterval: cardinal; // 每隔多長時間(ms)send乙個心跳包,發5次(系統值)
end;
tservercontainer1 = class(tdatamodule)
dsserver1: tdsserver;
dstcpservertransport1: tdstcpservertransport;
dsserverclass1: tdsserverclass;
procedure dsserverclass1getclass(dsserverclass: tdsserverclass;
var persistentclass: tpersistentclass);
procedure datamodulecreate(sender: tobject);
procedure dsserver1disconnect(dsconnecteventobject: tdsconnecteventobject);
procedure dsserver1connect(dsconnecteventobject: tdsconnecteventobject);
private
end;
varservercontainer1: tservercontainer1;
implementation
uses servermethodsunit1,mainform;
procedure tservercontainer1.datamodulecreate(sender: tobject);
begin
dsserver1.autostart :=false;
dstcpservertransport1.port :=g_port;
dsserver1.start;
end;
procedure tservercontainer1.dsserver1connect(
dsconnecteventobject: tdsconnecteventobject);
varclientconnection: tidtcpconnection;
val: ttcp_keepalive;
ret: dword;
begin
// 最大連線數量限制,驗證來訪者密碼
if (dsconnecteventobject.channelinfo = nil) or
(g_currentconnnum >= frmmain.maxclientnum) or
(dsconnecteventobject.connectproperties[tdbxpropertynames.username] <> g_username) or
(dsconnecteventobject.connectproperties[tdbxpropertynames.password] <> g_userpassword) then
begin
dsconnecteventobject.dbxconnection.destroy;
exit;
endelse
begin
inc(g_currentconnnum); // 記錄來訪者數量
//把心跳包放到服務端上執行,如果伺服器的某個tcp連線在5秒鐘沒有收到資料,
//將會傳送向對端傳送心跳包,間隔3秒鐘,連續傳送5次。如果5次以後對端還沒有應答,伺服器將結束該tcp連線
clientconnection := tidtcpconnection(dsconnecteventobject.channelinfo.id);
val.onoff := 1;
val.keepalivetime := 5000;
val.keepaliveinterval := 3000;
wsaioctl(clientconnection.socket.binding.handle, ioc_in or ioc_vendor or 4,
@val, sizeof(val), nil, 0, @ret, nil, nil);
end;
if dsconnecteventobject.channelinfo <> nil then
begin
dsshowdataset.findfield('clientid').asinteger := dsconnecteventobject.channelinfo.id;
dsshowdataset.findfield('clientip').asstring := clientconnection.socket.binding.peerip +
':' + inttostr(clientconnection.socket.binding.peerport);
dsshowdataset.findfield('serverip').asstring := clientconnection.socket.binding.ip + ':' +
inttostr(clientconnection.socket.binding.port);
end;
dsshowdataset.findfield('clientusername').asstring := dsconnecteventobject.connectproperties
[tdbxpropertynames.username];
dsshowdataset.findfield('clientuserpassword').asstring :=
dsconnecteventobject.connectproperties[tdbxpropertynames.password];
dsshowdataset.findfield('serverinfo').asstring := '上線';
dsshowdataset.post;
end;
end;
if dsconnecteventobject.channelinfo <> nil then
begin
clientconnection := tidtcpconnection(dsconnecteventobject.channelinfo.id);
dsshowdataset.findfield('clientid').asinteger := dsconnecteventobject.channelinfo.id;
dsshowdataset.findfield('clientip').asstring := clientconnection.socket.binding.peerip +
':' + inttostr(clientconnection.socket.binding.peerport);
dsshowdataset.findfield('serverip').asstring := clientconnection.socket.binding.ip + ':' +
inttostr(clientconnection.socket.binding.port);
end;
dsshowdataset.findfield('clientusername').asstring := dsconnecteventobject.connectproperties
[tdbxpropertynames.username];
dsshowdataset.findfield('clientuserpassword').asstring :=
dsconnecteventobject.connectproperties[tdbxpropertynames.password];
dsshowdataset.findfield('serverinfo').asstring := '下線';
dsshowdataset.post;
end;
dec(g_currentconnnum);
end;
procedure tservercontainer1.dsserverclass1getclass(
dsserverclass: tdsserverclass; var persistentclass: tpersistentclass);
begin
persistentclass := servermethodsunit1.tservermethods1;
end;
end.
MySQL 修改最大連線數限制
一 檢視最大連線數 mysql show variables like max connections 二 修改最大連線數 vim 編輯 etc mysql mysql.conf.d mysqld.cnf ubuntu vim 編輯 etc my.cnf centos 編輯以下引數 max conn...
最大連線數 Linux的檔案最大連線數
too many open files 檢視當前作業系統連線數設定 ulimit a修改伺服器最大連線數 vim etc security limits.conf新增 soft nofile 65535 hard nofile 65535 soft nproc 65535 hard nproc 65...
MYSQL 檢視最大連線數和修改最大連線數
mysql檢視最大連線數和修改最大連線數 1 檢視最大連線數 show variables like max connections 2 修改最大連線數 set global max connections 200 以下的文章主要是向大家介紹的是mysql最大連線數的修改,我們大家都知道mysql最...