我本机地址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);
}
在另一台电脑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);
}
保存连接,程序就可以运行了!