求一corba客户端和服务器程序,能跑揭帖
如题 问题点数:100、回复次数:2Top
1 楼jigangwang(wang)回复于 2006-08-03 17:53:09 得分 100
visibroker client
#include "CosNaming_c.hh"
#include "Bank_c.hh"
// USE_STD_NS is a define setup by VisiBroker to use the std namespace
USE_STD_NS
int main(int argc, char* const* argv)
{
try {
// Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Get a reference to the Naming Service root_context
CosNaming::NamingContext_var rootContext =
CosNaming::NamingContext::_narrow(
orb->resolve_initial_references("NameService"));
// Locate an account manager through the Naming Service
CosNaming::Name name;
name.length(1);
name[0].id = (const char *) "BankManager";
name[0].kind = (const char *) "";
Bank::AccountManager_var manager =
Bank::AccountManager::_narrow(rootContext->resolve(name));
// Use argv[1] as the account name, or a default
const char* account_name = argc > 1 ? argv[1] : "Jack B. Quick";
// Request the account manager to open a named account
Bank::Account_var account = manager->open(account_name);
// Get the balance of the account
CORBA::Float balance = account->balance();
// Print out the balance
cout << "The balance in " << account_name << "'s account is $"
<< balance << endl;
}
catch(const CORBA::Exception& e) {
cerr << e << endl;
return 1;
}
return 0;
}
server
#include "CosNaming_c.hh"
#include "BankImpl.h"
// USE_STD_NS is a define setup by VisiBroker to use the std namespace
USE_STD_NS
int main(int argc, char* const* argv)
{
try {
// Initialize the ORB.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// get a reference to the root POA
PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(
orb->resolve_initial_references("RootPOA"));
// get a reference to the Naming Service root_context
CosNaming::NamingContext_var rootContext =
CosNaming::NamingContext::_narrow(
orb->resolve_initial_references("NameService"));
CORBA::PolicyList policies;
policies.length(1);
policies[(CORBA::ULong)0] =
rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
// get the POA Manager
PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager();
// Create myPOA with the right policies
PortableServer::POA_var myPOA =
rootPOA->create_POA("bank_agent_poa", poa_manager, policies);
// Create the servant
AccountManagerImpl managerServant;
// Decide on the ID for the servant
PortableServer::ObjectId_var managerId =
PortableServer::string_to_ObjectId("BankManager");
// Activate the servant with the ID on myPOA
myPOA->activate_object_with_id(managerId, &managerServant);
// Activate the POA Manager
poa_manager->activate();
CORBA::Object_var reference = myPOA->servant_to_reference(&managerServant);
// Associate the bank manager with the name at the root context
CosNaming::Name name;
name.length(1);
name[0].id = (const char *) "BankManager";
name[0].kind = (const char *) "";
rootContext->rebind(name, reference);
cout << reference << " is ready" << endl;
// Wait for incoming requests
orb->run();
}
catch(const CORBA::Exception& e) {
cerr << e << endl;
return 1;
}
return 0;
}
使用了命名服务Top
2 楼jigangwang(wang)回复于 2006-08-03 17:54:19 得分 0
lz可以去安装目录找找
很多例子Top




