双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

RPC连接不上

贪玩的老鼠 贪玩的老鼠 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我本机地址192.168.18.252,在本机上运行服务,运行客户端,一切正常.
在另一台电脑192.168.18.169上运行客户端(服务器在我的电脑上已开启),GetLastError返回错误代码1326.
注:我的电脑可以通过网络访问(需要用户名和密码,可我不知道RpcStringBindingCompose怎么把密码用户写进去),防火墙已经关闭.
客户端代码如下:
int main()
{
unsigned char* pszStringBinding = NULL;

// 创建一个字符串绑定句柄.这里不进行连接.
if(RpcStringBindingCompose(
NULL, // 用于绑定的UUID.
(unsigned char*)("ncacn_np"), // 使用named pipe.
(unsigned char*)"\\\\192.168.18.252", // 网络地址.
(unsigned char*)("\\pipe\\hello"), // named pipe端口.
NULL, // 使用依赖网络的协议.
&pszStringBinding)) // 字符串绑定输出.
{
cout << "绑定错误!!!" << endl;
getchar();
return (1);
}


handle_t hRpcExplicitBinding = NULL;

// 确认字符串绑定句柄的格式并把它传换成一个绑定句柄.
// 这里也不进行连接.
if(RpcBindingFromStringBinding(
pszStringBinding, &hRpcExplicitBinding))
{
cout << "绑定错误ee!!!" << endl;
getchar();
return (1);
}

RpcTryExcept
{
char str[40]="Hello RPC World from RpcExplicitc!";

// 调用 RPC 函数,显式地使用绑定句柄 hRpcExplicitBinding.
// 这里进行连接.
RpcStringProc(hRpcExplicitBinding,(unsigned char*)str);

// 返回的结果.
cout << str << endl;

// 暂停.
getchar();
}
RpcExcept(1)
{
cerr <<"Runtime reported exception:"<<GetLastError()<< endl;
}
RpcEndExcept

// 调用远程过程完成,释放字符串和绑定句柄.
if(RpcStringFree(&pszStringBinding))
{
return (1);
}

// 释放绑定句柄资源并与服务程序断开.
if(RpcBindingFree(&hRpcExplicitBinding))
{
return (1);
}

return (0);
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
贪玩的老鼠
网络编程 18,356 成员 64,161 内容