Protocol.cpp
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:2k
源码类别:

游戏

开发平台:

Visual C++

  1. // Protocol.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "Protocol.h"
  5. #include "conio.h"
  6. #include "ProtocolFunc.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define CLIENT_CMDCONTENT "<CmdContent>"
  13. #define CLIENT_FROM "FromUserId"
  14. #define CLIENT_TO "ToUserId"
  15. #define CLIENT_CONTENT "Content"
  16. int main()
  17. {
  18. CString strBody="<Body> <CmdContent>FromUserId=Webmaster&ToUserId=chicken&Content=Hi,I need help;</CmdContent></Body>";
  19. CString strCmdContent;
  20. CString strKeyEnd;
  21. ProtocolFunc func;
  22. func.GetProtoLineEnd(CLIENT_CMDCONTENT,strKeyEnd);
  23. func.GetProtoContent(strBody,CLIENT_CMDCONTENT,strKeyEnd,strCmdContent);
  24. CPtrList listTemp;
  25. CString strSign=";";
  26. func.GetListBySign(strCmdContent,&listTemp,strSign);
  27. if(listTemp.GetCount()<=0)
  28. {
  29. func.ReleaseList(&listTemp);
  30. return 0;
  31. }
  32. POSITION pos=listTemp.FindIndex(0);
  33. LPNODESTRING pNodeString=(LPNODESTRING)listTemp.GetAt(pos);
  34. if(pNodeString==NULL)
  35. {
  36. func.ReleaseList(&listTemp);
  37. return 0;
  38. }
  39. strCmdContent=pNodeString->strContent;
  40. CPtrList listInfo;
  41. CString strMidSign="=";
  42. CString strEndSign="&";
  43. func.GetListByTwoSign(strCmdContent,&listInfo,strMidSign,strEndSign);
  44. CString strFrom,strTo,strContent;
  45. func.GetValueFromList(CLIENT_FROM,strFrom,&listInfo);
  46. func.GetValueFromList(CLIENT_TO,strTo,&listInfo);
  47. func.GetValueFromList(CLIENT_CONTENT,strContent,&listInfo);
  48. func.DeleteMateList(&listInfo);
  49. func.ReleaseList(&listTemp);
  50. printf("this is a test of get content from protocol:rn");
  51. printf("msg from %s to %s,content [%s]rn",strFrom,strTo,strContent);
  52. getch();
  53. return 0;
  54. }
  55. int SendMsg(CString strFrom,CString strTo,CString strContent)
  56. {
  57. ProtocolFunc func;
  58. CString strCmdContent;
  59. //增加content
  60. CPtrList MateList;
  61. LPNODEMATE pNodeMate=new NODEMATE;
  62. pNodeMate->strMateName =CLIENT_FROM;
  63. pNodeMate->strMateValue =strFrom;
  64. pNodeMate->strMateName =CLIENT_TO;
  65. pNodeMate->strMateValue =strTo;
  66. pNodeMate->strMateName =CLIENT_CONTENT;
  67. pNodeMate->strMateValue =strContent;
  68. MateList.AddTail(pNodeMate);
  69. func.ReplaceMateList(&MateList,strCmdContent);
  70. func.DeleteMateList(&MateList);
  71. //strCmdContent即为要发送的结构
  72. //send strCmdContent
  73. return 0;
  74. }