⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tserverlink_entity.cpp

📁 短信网管的原代码。用于与sp通信
💻 CPP
字号:
// TServerLink_Entity.cpp: implementation of the TServerLink_Entity class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PTChannel.h"
#include "Msg_Center.h"
#include "TServerLink_Entity.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CPTChannelApp theApp;
//本函数被socket线程调用     
BOOL TServerLink_Entity::OnTcpDataInd(char Buff[],int BufLen) //收到TCP消息
{
   STRUCT_CMPP12_MSG_HEADER *pHead;
   DWORD dwMsgTye;

   iSendLinkTestCount = 0;//用来判断协议实体连接是否正常
   pHead = (STRUCT_CMPP12_MSG_HEADER *)Buff;
   dwMsgTye = ntohl(pHead->dwCommand_ID);
   switch(dwMsgTye)
   {
		case CMPP12_CONNECT:
			STRUCT_SGIP_CONNECT *pMsg;
			pMsg = (STRUCT_SGIP_CONNECT *)Buff;
			LogTest("Rcv a  ESME_BNDRCV from SgipLink !\r\n");
			//???此处差登陆的密码、类型与登陆名的判断
			Login_Rep();
			break;
/*		case CMPP12_CONNECT_REP:
			STRUCT_SGIP_CONNECT_REP *pMsg;
			pMsg = (STRUCT_SGIP_CONNECT_REP *)Buff;
			LogTest("Rcv a  ESME_BNDRCV_RESP from CmppLink !\r\n");
			if(pMsg->btResult == BYTE(E_SUCCESS))
		    	SetEvent(m_LogSucc);//通知收到连接成功
			break;*/
		case CMPP12_TERMINATE:
			{
  				LogTest("Rcv a  CMPP12_TERMINATE from CmppLink !\r\n");
				SGIP_MSGHEAD* sUnbind = (SGIP_MSGHEAD*)Buff;
				sUnbind->Command_ID   = htonl(0x80000002);
				SendToTcp((char*)sUnbind,sizeof(SGIP_MSGHEAD));
				return FALSE;
				break;
			}
		case CMPP12_TERMINATE_REP:
  	        LogInf("Rcv a  CMPP12_TERMINATE_REP from CmppLink !\r\n");
			return FALSE;
			break;
		case CMPP12_ACTIVE_TEST:
  	        LogTest("Rcv a  CMPP12_ACTIVE_TEST from CmppLink !\r\n");
		//	SendLinkTestRsp();
			break;
		case CMPP12_ACTIVE_TEST_REP:
			LogTest("Rcv a  CMPP12_ACTIVE_TEST_REP from CmppLink !\r\n");
			break;
		case SGIP_DELIVERY:
			{
				MoAdd();
				LogMsg(Buff);//数出输出消息
				STRUCT_DELIVERY sDelivery;
				DELIVER* sSGIPDelivery = (DELIVER*)Buff;

				STRUCT_SGIP_DELIVERY_REP sDeliveryRep;
				ZeroMemory(&sDeliveryRep,sizeof(STRUCT_SGIP_DELIVERY_REP));
				sDeliveryRep.sHeader.Command_ID = htonl(SGIP_DELIVERY_REP);
				memcpy(&sDeliveryRep.sHeader.Sequence_ID,&sSGIPDelivery->sHeader.Sequence_ID,12);
				sDeliveryRep.sHeader.Total_Length = htonl(sizeof(STRUCT_SGIP_DELIVERY_REP));
				sDeliveryRep.btResult = 0;

				SendToTcp((char*)&sDeliveryRep,sizeof(STRUCT_SGIP_DELIVERY_REP));
				theApp.center->SGIP_Deliver(Buff,BufLen);
				break;
			}
		case SGIP_REPORT:
			{
				LogMsg(Buff);//数出输出消息
				STRUCT_MSG_REPORT sMsgReport;
				STRUCT_SGIP_REPORT* sSGIPReport = (STRUCT_SGIP_REPORT*)Buff;
				
				STRUCT_SGIP_REPORT_REP sReportRep;
				ZeroMemory(&sReportRep,sizeof(STRUCT_SGIP_REPORT_REP));
				sReportRep.sHeader.Command_ID = htonl(SGIP_REPORT_REP);
				memcpy(&sReportRep.sHeader.Sequence_ID,&sSGIPReport->sHeader.Sequence_ID,12);
				sReportRep.sHeader.Total_Length = htonl(sizeof(STRUCT_SGIP_REPORT_REP));
				sReportRep.btResult = 0;

				SendToTcp((char*)&sReportRep,ntohl(sReportRep.sHeader.Total_Length));
				theApp.center->SGIP_Report(Buff,BufLen);
				break;
			}
        default:
		  if(MsgQue.push(Buff, BufLen)!=1)
				LogErr("TServerLink_Entity Push message error!\r\n");
        break;
   }
   return TRUE;
}

int TServerLink_Entity::Login_Rep()        //登陆服务器,阻塞式登陆
{
	//登陆应用代理系统
/*	char buf[200];
	int bufLen;

	//组连接登陆包connect_msg
	STRUCT_CHANNEL_CONNECT struct_channel_connect;
	ZeroMemory(&struct_channel_connect,sizeof(STRUCT_CHANNEL_CONNECT));

	struct_channel_connect.sHeader.dwCommandId=htonl(TRP_CHANNEL_CONNECT);
	struct_channel_connect.sHeader.dwTotalLen=htonl(sizeof(STRUCT_CHANNEL_CONNECT));

	memcpy(&struct_channel_connect.szChannelName,gStructChannelInfo.szChannelName,sizeof(gStructChannelInfo.szChannelName));
	memcpy(&struct_channel_connect.szPwd,gStructChannelInfo.szPwd,sizeof(gStructChannelInfo.szPwd));
	struct_channel_connect.cChannelProtocol=gStructChannelInfo.ChannelProtocol;
	struct_channel_connect.cChannelType=gStructChannelInfo.ChannelType;

	memcpy(&buf,&struct_channel_connect,sizeof(STRUCT_CHANNEL_CONNECT));

	bufLen=sizeof(STRUCT_CHANNEL_CONNECT);*/
	//连接数据缓冲区
	STRUCT_SGIP_CONNECT_REP con;
	ZeroMemory(&con,sizeof con);
	con.sHeader.Total_Length=htonl(sizeof STRUCT_SGIP_CONNECT_REP);
	con.sHeader.Command_ID=htonl(0x80000001);//SGIP_BIND
	con.sHeader.Sequence_ID.seq=htonl(1);

	con.btResult = 0;//成功

    if((SendToTcp((char*)&con,sizeof con) )==TRUE)
    {
		m_LlcConnected = TRUE;//登陆成功
		return TRUE;
	}
	return FALSE;
}

int  TServerLink_Entity::Logout()       //退出服务器
{
	return 0;
}

BOOL TServerLink_Entity::SendLinkTest_Rep() //发送测试消息
{
	STRUCT_CMPP12_ACTIVE_TEST cmpp_active_test;
	ZeroMemory(&cmpp_active_test,sizeof(STRUCT_CMPP12_ACTIVE_TEST));

	cmpp_active_test.sHeader.dwCommand_ID=htonl(CMPP12_ACTIVE_TEST);
	cmpp_active_test.sHeader.dwSequence_ID=htonl(GET_SEQ_NO);
	cmpp_active_test.sHeader.dwTotal_Length=htonl(12);

	iSendLinkTestCount ++;	
	return(SendToTcp((char *)&cmpp_active_test, sizeof(STRUCT_CMPP12_ACTIVE_TEST)));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -