DIOCP转发型中间网关
Posted diocp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DIOCP转发型中间网关相关的知识,希望对你有一定的参考价值。
处理部分关键代码:
中转类网关处理部分:
procedure DiocpExecute(pvCMDObject: TSimpleMsgPack; pvContext:TDiocpStreamClientContext);
var
lvCMDIndex:Integer;
lvSession:TCHATSession;
ToUserID:string;
DataDBID:string;
begin
if pvCMDObject.O[‘ResultCMD‘]<> nil then
begin
ToUserID:=pvCMDObject.ForcePathObject(‘FrmUser‘).asstring;
pvCMDObject.ForcePathObject(‘CMD‘).AsInteger:=pvCMDObject.ForcePathObject(‘ResultCMD‘).asinteger;
pvCMDObject.DeleteObject(‘ResultCMD‘);
SendCMDObject(pvCMDObject,TCHATSession(ChatSessions.FindSession(ToUserID)).FContext);
pvCMDObject.clear;
exit;
end;
if pvCMDObject.O[‘cmd‘]<> nil then
begin
lvCMDIndex := pvCMDObject.ForcePathObject(‘cmd‘).AsInteger;
case lvCMDIndex of
0: ExecuteHeart (pvCMDObject, pvContext); // 心跳
1: ExecuteLogin (pvCMDObject, pvContext); // 登陆
10: ExecuteSql (pvCMDObject, pvContext);
else //转发数据给处理端
begin
lvSession := TCHATSession(TDiocpStreamClientContext(pvContext).Data);
if lvSession = nil then
begin
raise exception.CreateFmt(pvContext.RemoteAddr+‘[‘+inttostr(pvcontext.RemotePort) +‘]非法连接关闭:[%d]‘, [lvCMDIndex]);
end
else
begin
pvCMDObject.ForcePathObject(‘FrmUser‘).asstring:=lvSession.useriD;
if DataDBSrv.count>0 then
begin
Randomize;
DataDBID:=DataDBSrv.strings[Random(DataDBSrv.count)];
// sflogger.logMessage(datadbid);
end
else
begin
sflogger.logMessage(‘处理端未开启‘);
end;
SendCMDObject(pvCMDObject,TCHATSession(ChatSessions.FindSession(DataDBID)).FContext);
end;
// sfLogger.logMessage(‘转发成功‘);
exception.CreateFmt(pvContext.RemoteAddr+‘[‘+inttostr(pvcontext.RemotePort) +‘]执行未知命令:[%d]‘, [lvCMDIndex]);
end;
end;
end;
end;
以上是关于DIOCP转发型中间网关的主要内容,如果未能解决你的问题,请参考以下文章