Skip to content

Commit 40893e2

Browse files
committed
update:p2p and image example
1 parent b504b4f commit 40893e2

File tree

3 files changed

+85
-32
lines changed

3 files changed

+85
-32
lines changed

XEngine_APPClient/APPClient_ImageExample/APPClient_ImageExample.cpp

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,107 @@
22
#include <Windows.h>
33
#include <tchar.h>
44
#pragma comment(lib,"Ws2_32")
5+
#pragma comment(lib,"jsoncpp")
56
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
67
#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient")
8+
#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi")
79
#endif
810
#include <stdio.h>
911
#include <stdlib.h>
1012
#include <string.h>
1113
#include <inttypes.h>
14+
#include <json/json.h>
1215
#include <XEngine_Include/XEngine_CommHdr.h>
1316
#include <XEngine_Include/XEngine_Types.h>
1417
#include <XEngine_Include/XEngine_ProtocolHdr.h>
1518
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
1619
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
1720
#include <XEngine_Include/XEngine_NetHelp/APIClient_Define.h>
1821
#include <XEngine_Include/XEngine_NetHelp/APIClient_Error.h>
22+
#include <XEngine_Include/XEngine_SystemSdk/ProcFile_Define.h>
23+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
24+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
1925

2026
//需要优先配置XEngine
2127
//WINDOWS支持VS2022 x64 debug 编译调试
2228
//linux::g++ -std=c++17 -Wall -g APPClient_ImageExample.cpp -o APPClient_ImageExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIClient
2329
//macos::g++ -std=c++17 -Wall -g APPClient_ImageExample.cpp -o APPClient_ImageExample.exe -lXEngine_BaseLib -lNetHelp_APIClient
2430

2531

26-
int test_query()
32+
bool APPClient_ImageExample_GetAttr(LPCXSTR lpszMsgBuffer, int nMsgLen, int* pInt_Width, int* pInt_Height)
2733
{
2834
int nCode = 0;
29-
XCHAR* ptszFileBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX);
30-
if (NULL == ptszFileBuffer)
31-
{
32-
return -1;
33-
}
34-
memset(ptszFileBuffer, '\0', XENGINE_MEMORY_SIZE_MAX);
35-
3635
LPCXSTR lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=image&params1=0");
3736

38-
FILE* pSt_File = _xtfopen(_X("D:\\XEngine_APIService\\XEngine_APPClient\\x64\\Debug\\1.png"), "rb");
39-
int nRet = fread(ptszFileBuffer, 1, XENGINE_MEMORY_SIZE_MAX, pSt_File);
40-
4137
XCHAR* ptszMsgBuffer = NULL;
42-
if (!APIClient_Http_Request(_X("POST"), lpszAPIUrl, ptszFileBuffer, &nCode, &ptszMsgBuffer, &nRet))
38+
if (!APIClient_Http_Request(_X("POST"), lpszAPIUrl, lpszMsgBuffer, &nCode, &ptszMsgBuffer, &nMsgLen))
4339
{
4440
printf("发送投递失败!\n");
4541
return 0;
4642
}
47-
printf("接受到数据,大小:%d,内容:%s\n", nRet, ptszMsgBuffer);
43+
Json::Value st_JsonRoot;
44+
JSONCPP_STRING st_JsonError;
45+
Json::CharReaderBuilder st_JsonBuilder;
46+
//开始解析配置文件
47+
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
48+
if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
49+
{
50+
printf("json parse failed\n");
51+
return false;
52+
}
4853
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
49-
free(ptszFileBuffer);
54+
55+
Json::Value st_JsonBase = st_JsonRoot["st_BaseInfo"];
56+
*pInt_Width = st_JsonBase["nWidth"].asInt();
57+
*pInt_Height = st_JsonBase["nHeigth"].asInt();
58+
return 0;
59+
}
60+
int test_imgzoom()
61+
{
62+
LPCXSTR lpszFileDir = _X("D:\\Image\\*.png");
63+
64+
int nListCount = 0;
65+
XCHAR** pptszListFile;
66+
67+
SystemApi_File_EnumFile(lpszFileDir, &pptszListFile, &nListCount);
68+
for (int i = 0; i < nListCount; i++)
69+
{
70+
int nCode = 0;
71+
int nWidth = 0;
72+
int nHeight = 0;
73+
XCHAR* ptszFileBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX);
74+
if (NULL == ptszFileBuffer)
75+
{
76+
return -1;
77+
}
78+
memset(ptszFileBuffer, '\0', XENGINE_MEMORY_SIZE_MAX);
79+
80+
FILE* pSt_File = _xtfopen(pptszListFile[i], _X("rb"));
81+
int nRet = (int)fread(ptszFileBuffer, 1, XENGINE_MEMORY_SIZE_MAX, pSt_File);
82+
fclose(pSt_File);
83+
APPClient_ImageExample_GetAttr(ptszFileBuffer, nRet, &nWidth, &nHeight);
84+
85+
XCHAR tszAPIUrl[MAX_PATH];
86+
memset(tszAPIUrl, '\0', sizeof(tszAPIUrl));
87+
88+
_xstprintf(tszAPIUrl, _X("http://127.0.0.1:5501/api?function=image&type=1&ext=png&width=%d&height=%d"), nWidth / 2, nHeight / 2);
89+
90+
XCHAR* ptszMsgBuffer = NULL;
91+
if (!APIClient_Http_Request(_X("POST"), tszAPIUrl, ptszFileBuffer, &nCode, &ptszMsgBuffer, &nRet))
92+
{
93+
printf("发送投递失败!\n");
94+
return 0;
95+
}
96+
free(ptszFileBuffer);
97+
98+
pSt_File = _xtfopen(pptszListFile[i], _X("wb"));
99+
fwrite(ptszMsgBuffer, 1, nRet, pSt_File);
100+
fclose(pSt_File);
101+
102+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
103+
}
104+
105+
50106
return 0;
51107
}
52108

@@ -56,7 +112,8 @@ int main()
56112
WSADATA st_WSAData;
57113
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
58114
#endif
59-
test_query();
115+
116+
test_imgzoom();
60117

61118
#ifdef _MSC_BUILD
62119
WSACleanup();

XEngine_APPClient/APPClient_ImageExample/APPClient_ImageExample.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
</ImportGroup>
7272
<PropertyGroup Label="UserMacros" />
7373
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74-
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
75-
<LibraryPath>$(XEngine_Lib64);$(LibraryPath)</LibraryPath>
74+
<IncludePath>$(XEngine_Include);../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(IncludePath)</IncludePath>
75+
<LibraryPath>$(XEngine_Lib64);../../XEngine_Source/x64/Debug;$(LibraryPath)</LibraryPath>
7676
</PropertyGroup>
7777
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7878
<ClCompile>

XEngine_APPClient/APPClient_P2PExample/APPClient_P2PExample.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BOOL APIHelp_NetWork_GetIPNet(XCHAR* ptszIPAddr)
5252
int APPClient_P2XPLogin()
5353
{
5454
Json::Value st_JsonRoot;
55-
LPCXSTR lpszAddr = _T("http://192.168.1.8:5501/api?function=p2p&params1=24577");
55+
LPCXSTR lpszAddr = _T("http://127.0.0.1:5501/api?function=p2p&params1=24577");
5656
ENUM_XENGINE_NETXAPI_SOCKET_CONNECTTYPE dwNetType;
5757

5858
memset(tszPublicAddr, '\0', sizeof(tszPublicAddr));
@@ -95,7 +95,7 @@ int APPClient_P2XPLogin()
9595
int APPClient_P2XPList()
9696
{
9797
Json::Value st_JsonRoot;
98-
LPCXSTR lpszAddr = _T("http://192.168.1.8:5501/api?function=p2p&params1=24579");
98+
LPCXSTR lpszAddr = _T("http://127.0.0.1:5501/api?function=p2p&params1=24581");
9999

100100
st_JsonRoot["tszUserName"] = lpszUserName;
101101
st_JsonRoot["tszPrivateAddr"] = tszPrivateAddr;
@@ -113,31 +113,27 @@ int APPClient_P2XPList()
113113
return 0;
114114
}
115115

116-
int APPClient_P2XPGetUser()
116+
int APPClient_P2XPWan()
117117
{
118118
Json::Value st_JsonRoot;
119-
LPCXSTR lpszAddr = _T("http://192.168.1.8:5501/api?function=p2p&params1=24583");
120-
121-
st_JsonRoot["tszUserName"] = lpszUserName;
122-
st_JsonRoot["tszPrivateAddr"] = tszPrivateAddr;
123-
st_JsonRoot["tszPublicAddr"] = tszPublicAddr;
119+
LPCXSTR lpszAddr = _T("http://127.0.0.1:5501/api?function=p2p&params1=24583");
124120

125121
int nMsgLen = 0;
126122
int nHTTPCode = 0;
127123
XCHAR* ptszMsgBuffer = NULL;
128-
if (!APIClient_Http_Request(_T("POST"), lpszAddr, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen))
124+
if (!APIClient_Http_Request(_T("POST"), lpszAddr, NULL, &nHTTPCode, &ptszMsgBuffer, &nMsgLen))
129125
{
130126
return -1;
131127
}
132-
printf("APPClient_P2XPGetUser,&nMsgLen:%d,%s\n", nMsgLen, ptszMsgBuffer);
128+
printf("APPClient_P2XPWan,&nMsgLen:%d,%s\n", nMsgLen, ptszMsgBuffer);
133129
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
134130
return 0;
135131
}
136132

137-
int APPClient_P2XPConnect()
133+
int APPClient_P2XPLogout()
138134
{
139135
Json::Value st_JsonRoot;
140-
LPCXSTR lpszAddr = _T("http://192.168.1.8:5501/api?function=p2p&params1=24581");
136+
LPCXSTR lpszAddr = _T("http://127.0.0.1:5501/api?function=p2p&params1=24579");
141137

142138
st_JsonRoot["tszUserName"] = lpszUserName;
143139
st_JsonRoot["tszPrivateAddr"] = tszPrivateAddr;
@@ -150,7 +146,7 @@ int APPClient_P2XPConnect()
150146
{
151147
return -1;
152148
}
153-
printf("APPClient_P2XPConnect,&nMsgLen:%d,%s\n", nMsgLen, ptszMsgBuffer);
149+
printf("APPClient_P2XPLogout,&nMsgLen:%d,%s\n", nMsgLen, ptszMsgBuffer);
154150
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
155151
return 0;
156152
}
@@ -164,8 +160,8 @@ int main()
164160

165161
APPClient_P2XPLogin();
166162
APPClient_P2XPList();
167-
//APPClient_P2XPGetUser();
168-
//APPClient_P2XPConnect();
163+
APPClient_P2XPWan();
164+
APPClient_P2XPLogout();
169165

170166
#ifdef _MSC_BUILD
171167
WSACleanup();

0 commit comments

Comments
 (0)