- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Protocol.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:2k
源码类别:
游戏
开发平台:
Visual C++
- // Protocol.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "Protocol.h"
- #include "conio.h"
- #include "ProtocolFunc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define CLIENT_CMDCONTENT "<CmdContent>"
- #define CLIENT_FROM "FromUserId"
- #define CLIENT_TO "ToUserId"
- #define CLIENT_CONTENT "Content"
- int main()
- {
- CString strBody="<Body> <CmdContent>FromUserId=Webmaster&ToUserId=chicken&Content=Hi,I need help;</CmdContent></Body>";
- CString strCmdContent;
- CString strKeyEnd;
- ProtocolFunc func;
- func.GetProtoLineEnd(CLIENT_CMDCONTENT,strKeyEnd);
- func.GetProtoContent(strBody,CLIENT_CMDCONTENT,strKeyEnd,strCmdContent);
- CPtrList listTemp;
- CString strSign=";";
- func.GetListBySign(strCmdContent,&listTemp,strSign);
- if(listTemp.GetCount()<=0)
- {
- func.ReleaseList(&listTemp);
- return 0;
- }
- POSITION pos=listTemp.FindIndex(0);
- LPNODESTRING pNodeString=(LPNODESTRING)listTemp.GetAt(pos);
- if(pNodeString==NULL)
- {
- func.ReleaseList(&listTemp);
- return 0;
- }
- strCmdContent=pNodeString->strContent;
- CPtrList listInfo;
- CString strMidSign="=";
- CString strEndSign="&";
- func.GetListByTwoSign(strCmdContent,&listInfo,strMidSign,strEndSign);
- CString strFrom,strTo,strContent;
- func.GetValueFromList(CLIENT_FROM,strFrom,&listInfo);
- func.GetValueFromList(CLIENT_TO,strTo,&listInfo);
- func.GetValueFromList(CLIENT_CONTENT,strContent,&listInfo);
- func.DeleteMateList(&listInfo);
- func.ReleaseList(&listTemp);
- printf("this is a test of get content from protocol:rn");
- printf("msg from %s to %s,content [%s]rn",strFrom,strTo,strContent);
- getch();
- return 0;
- }
- int SendMsg(CString strFrom,CString strTo,CString strContent)
- {
- ProtocolFunc func;
- CString strCmdContent;
- //增加content
- CPtrList MateList;
- LPNODEMATE pNodeMate=new NODEMATE;
- pNodeMate->strMateName =CLIENT_FROM;
- pNodeMate->strMateValue =strFrom;
- pNodeMate->strMateName =CLIENT_TO;
- pNodeMate->strMateValue =strTo;
- pNodeMate->strMateName =CLIENT_CONTENT;
- pNodeMate->strMateValue =strContent;
- MateList.AddTail(pNodeMate);
- func.ReplaceMateList(&MateList,strCmdContent);
- func.DeleteMateList(&MateList);
- //strCmdContent即为要发送的结构
- //send strCmdContent
- return 0;
- }