gpt4 book ai didi

c++ - C++ : Can multiple Clients listen to one server when endpoint is hard coded? 中的远程过程调用 (RPC)

转载 作者:行者123 更新时间:2023-11-28 01:44:04 25 4
gpt4 key购买 nike

我正在使用 MIDLRPC 编写一个简单的服务器客户端以允许文件传输。它在端点硬编码如下时有效:

服务器端

status = RpcServerUseProtseqEp(  
reinterpret_cast<unsigned char*>("ncacn_ip_tcp"),
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
reinterpret_cast<unsigned char*>("8888"),
NULL);

客户端

status = RpcStringBindingCompose(NULL,
"ncacn_ip_tcp",
(RPC_CSTR)"127.0.0.1",
"8888",
NULL,
NULL);

我想知道当端点被硬编码时,多个客户端是否能够连接到一台服务器?正如我们所知,在使用 TCP 协议(protocol)的套接字编程中,两个应用程序不能同时连接到一个端口。但是,MSDN 引用资料指出,RPC 服务器进程使用先进先出调用队列来处理请求。

如果无法接收来自客户端的多个请求,是否可以设置端点池?谢谢。

最佳答案

你混淆了这里的术语。

服务器 正在监听 TCP 端口。这意味着它绑定(bind)到端口并在其上启动接受循环。每次新客户端连接到此端口时,accept 函数都会与该客户端建立 TCP 连接,然后返回监听端口。

服务器应用程序要么是多线程应用程序,要么是同时处理多个操作的异步应用程序:监听新客户端、与每个连接的客户端通信并执行实际工作。

典型的 RPC 服务器看起来像这样

status = RpcServerUseProtseqEp(pszProtocolSequence,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
pszEndpoint,
pszSecurity);

if (status) exit(status);

status = RpcServerRegisterIf(my_rpc_interface_spec,
NULL,
NULL);

if (status) exit(status);

status = RpcServerListen(cMinCalls,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
0);

if (status) exit(status);

RpcServerListen 调用将永远阻塞,启动 cMinCalls 工作线程并执行 accept 循环,接受连接并处理向上的请求到 cMinCalls 并行线程。

关于c++ - C++ : Can multiple Clients listen to one server when endpoint is hard coded? 中的远程过程调用 (RPC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45941166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com