dxsock 服务端代码(100分)

  • 主题发起人 主题发起人 dkq811230
  • 开始时间 开始时间
D

dkq811230

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TfrmMain.ClientNewConnect(ClientThread: TDXClientThread);
var
ptrData:PClient;
begin
new(ptrData);
with ptrData^ do
begin
boolLoginIn :=false;
intLogTimes :=0;
strClientId :='';
strClientName :='';
strRecDataTmp :='';
end;
ClientThread.fpSessionData:=ptrData;
memConn.Lines.Add('连接信息:-> '+stringofchar(' ',6)+'远程主机: '+
ClientThread.Socket.PeerIPAddress
+stringofchar(' ',5)+stringofchar(' ',4)+'远程端口: '+ IntToStr(ClientThread.Socket.PeerPort)
+stringofchar(' ',4)+'接入时间: '+formatdatetime('yyyy-mm-dd hh:mm:ss',now));
RefreshStatusBar;
end;
procedure TfrmMain.ClientCloseConnect(ClientThread: TDXClientThread);
begin
try
if Assigned(PClient(ClientThread.fpSessionData)) then Dispose(PClient(ClientThread.fpSessionData));
ClientThread.fpSessionData := nil;
except
end;
memConn.Lines.Add('退出信息:-> '+stringofchar(' ',6)+'远程主机: '+ClientThread.Socket.PeerIPAddress
+stringofchar(' ',5)+stringofchar(' ',4)
+'远程端口: '+ IntToStr(ClientThread.Socket.PeerPort)
+stringofchar(' ',4)+'退出时间: '+formatdatetime('yyyy-mm-dd hh:mm:ss',now));
RefreshStatusBar;
end;



procedure TfrmMain.DxServerNewConnect(ClientThread: TDXClientThread);
var
strTmp:string;
intPos:integer;
IntLen,intLenTerminate:integer;
strData:string;
varValue:Variant;
num:longint;
strReceiveData,strTheEnd:string;
ReceBuff :array of char;
begin
ClientNewConnect(ClientThread) ;
while ClientThread.Socket.Connected do
begin

if ClientThread.Socket.Readable then
begin
If ClientThread.Socket.CharactersToRead=0 then break; // disconnect
num:=ClientThread.Socket.CharactersToRead;
SetLength(ReceBuff, num);
//组合接收的数据为一个完整的数据包
ClientThread.Socket.ReceiveBuf(pointer(ReceBuff)^,num) ;
strReceiveData:=string(ReceBuff);
strData:=strReceiveData;
try
memReceData.Lines.Add('接收信息:->'+stringofchar(' ',5)+'来自主机: '+ ClientThread.Socket.PeerIPAddress
+stringofchar(' ',5)+stringofchar(' ',4)+
'消息长度:'+inttostr(Length(strData))+stringofchar(' ',4)+'消息内容:'+strData);
except
end;
IntLen:=strtoIntdef(copy(strData,1,4),0)+4;
intLenTerminate:=length(gcstrTerminate);
strTheEnd:=copy(strData,IntLen-intLenTerminate+1,intLenTerminate);
while strTheEnd=gcstrTerminate do
begin
strTmp:=copy(strData,1,IntLen+intLenTerminate-1);
delete(strData,1,IntLen+intLenTerminate-1);
ProcessMsg(ClientThread.Socket,strTmp);
IntLen:=strtoIntdef(copy(strData,1,4),0)+4;
strTheEnd:=copy(strData,IntLen-intLenTerminate+1,intLenTerminate);
end;
end
else
begin
DXString.DoSleepEx(1);
DXString.ProcessWindowsMessageQueue;
end;
end;
ClientCloseConnect(ClientThread);
end;


procedure TfrmMain.DxServerMaxConnects(
ServerCoreThread: TDXServerCoreThread);
begin
memError.Lines.Add('错误信息->:已达到最大连接数'+inttostr(ServerCoreThread.ActiveNumberOfConnections));
end;
 
dxsock 服务端最新版本支持iocp吗?
 
后退
顶部