RCPServer.h
上传用户:hyz2004817
上传日期:2022-03-30
资源大小:226k
文件大小:2k
- #ifndef _RCPSERVER_H_
- #define _RCPSERVER_H_
- ///////////////////////////////////////////////
- //
- // 帮助宏
- #define SERVER_LISTEN_PORT 4813
- #define SAFE_DELETE_ARRAY(x) if(x!=NULL) { delete[] x; x = NULL; }
- #define SAFE_CLOSE_HANDLE(x) if(x!=NULL) { CloseHandle( x ); x = NULL; }
- #define WSAERRORSTRING (WSAErrorString(WSAGetLastError()))
- #ifdef _DEBUG // 调试输出宏
- #define DEBUGOUTPUT1(x) cout << x << endl;
- #define DEBUGOUTPUT2(x, y) cout << x << y << endl;
- #define DEBUGOUTPUT3(x, y, z) cout << x << y << z << endl;
- #else
- #define DEBUGOUTPUT1(x)
- #define DEBUGOUTPUT2(x, y)
- #define DEBUGOUTPUT3(x, y, z)
- #endif
- #define WM_RCASERVEREXIT (WM_USER+100)
- // 定义应答状态码
- #define RCA_RESPONSE_200_OK 200
- #define RCA_RESPONSE_404_NOTFOUND 404
- #define RCA_RESPONSE_808_BYEBYE 808
- #define RCA_RESPONSE_502_FAILED 502
- ///////////////////////////////////////////
- // RCA 协议头结构 大小为 40 个字节
- //
- typedef struct _RCARequestHeader{
- char rcaID[4]; // "RCA "
- DWORD dwHeaderType; // header type
- BOOL bNeedResponse; // 是否需要应答
- WORD wMajorVersion; // 主版本号
- WORD wMinorVersion; // 次版本号
- DWORD dwRequestID; // 请求操作的 ID 号
- DWORD requestBytes; // 请求的总字节数
- char reserved[16]; // 保留 24 个字节
- } RCAREQUESTHEADER, *PRCAREQUESTHEADER;
- typedef struct _RCAResponseHeader {
-
- char rcaID [4]; // RCA ID "RCA "
- DWORD dwHeaderType; // RCA header type
- DWORD dwStatusCode; // RCA response status code
- DWORD dwTotalBytes; // response total bytes
-
- char reserved[24]; // 保留 28 个字节
- }RCARESPONSEHEADER, *PRCARESPONSEHEADER;
- #define RCAHEADER_TYPE_REQUEST 1 // 请求头
- #define RCAHEADER_TYPE_RESPONSE 2 // 响应头
- #define RCAHEADER_TYPE_KEEPALIVE 3 // 保活包
- typedef struct _RCAKeepAliveHeader {
- char rcaID[4];
- DWORD dwHeaderType;
- char reserved[32];
- }RCAKEEPALIVEHEADER, *PRCAKEEPALIVEHEADER;
- typedef struct _RCAHeader {
- char rcaID[4];
- DWORD dwHeaderType;
- char reserved[32];
- }RCAHEADER, *PRCAHEADER;
- typedef struct _RCARequestHandleData {
-
- SOCKET sockRemote;
- DWORD dwRemoteAddress;
- DWORD dwRemotePort;
- DWORD reserved;
- } RCAREQUESTHANDLEDATA;
- // 一个根据特定ID 进行处理的函数的指针类型
- typedef
- BOOL
- ( WINAPI *RCAREQUESTIDHANDLER)
- (
- SOCKET sockRemote,
- RCAREQUESTHANDLEDATA* pData,
- RCAREQUESTHEADER * pRCAHead,
- HANDLE hEventArray[2]
- );
- #endif