为客户端生成RPC代码以远程调用现有服务器功能?

在我问主要问题之前,我有两个基于套接字的现有客户端/服务器win32项目,其中客户端向服务器发送字符串请求,并使用套接字函数send(),recv( )

服务器代码的一部分(当前仍基于套接字)

struct client_ctx
{
    int socket;
    CHAR buf_recv[MAX_SEND_BUF_SIZE]; // receive buffer
    CHAR buf_send[MAX_SEND_BUF_SIZE]; // send buffer
    unsigned int sz_recv; // size of recv buffer
    unsigned int sz_send_total; // size of send buffer
    unsigned int sz_send; // size of data send
                          // OVERLAPPED structures for notifications of completition 
    OVERLAPPED overlap_recv;
    OVERLAPPED overlap_send;
    OVERLAPPED overlap_cancel;
    DWORD flags_recv; // flags for WSARecv
};
struct client_ctx g_ctxs[1 + MAX_CLIENTS];

void schedule_write(DWORD idx)
{
    WSABUF buf; buf.buf = g_ctxs[idx].buf_send + g_ctxs[idx].sz_send;
    buf.len = g_ctxs[idx].sz_send_total - g_ctxs[idx].sz_send;
    memset(&g_ctxs[idx].overlap_send,sizeof(OVERLAPPED));
    WSASend(g_ctxs[idx].socket,&buf,1,NULL,&g_ctxs[idx].overlap_send,NULL);
}

使用上述功能,我将请求的数据发送到客户端

我从服务器发送的数据

static class SystemInfo{
public :
    static std::string GetOSVersion();
    static std::string getcurrentTimeStr();
    static std::string GetTimeSinceStartStr();
    static std::string GetFreeMemoryStr();
    static std::string GetFreeSpaceStr();
    static std::string Checkaccess();
    static std::string CheckKeyFileDirectoryaccessRights(wchar_t *char_path,wchar_t *char_buf);
    static std::string usernameFromSid(PSID userSid);
    static BOOL FileOrDirectoryExists(LPCTSTR szPath);
};

问题是:关于如何使用Midl编译器将 SystemInfo 类中的方法表示为可以远程调用的过程,是否有任何指南?我找不到如何将现有功能与远程过程调用连接(在我的情况下是从客户端使用它们)

的任何手册。
xxd1111 回答:为客户端生成RPC代码以远程调用现有服务器功能?

您将无法直接将客户端调用挂接到现有服务器功能。即使在客户端使用隐式绑定句柄时,实际的服务器功能也会获得绑定句柄(否则服务器将无法处理多个客户端)。因此,签名根本不匹配。

本文链接:https://www.f2er.com/3108870.html

大家都在问