예제 #1
0
int main()
{
	try
	{
		RCF::init();
		HelloWorld helloWorld;

		RCF::RcfServer server;
		// 捕获服务端的传输层
		RCF::ServerTransport &tcpTransport = server.addEndpoint(RCF::TcpEndpoint(50001));
		RCF::ServerTransport &udpTransport = server.addEndpoint(RCF::UdpEndpoint(50001));
		// 如果服务端只有一个传输层,则可以使用getServerTransport()
		// RCF::ServerTransport &transport = server.getServerTransport();
		server.bind<I_HelloWorld>(helloWorld);
		server.start();

		RcfClient<I_HelloWorld> client(RCF::TcpEndpoint(50001));
		// 客户端获取传输层
		RCF::ClientTransport &clientTransport = client.getClientStub().getTransport();
		client.Print("我是客户端");

		close();
	}
	catch (RCF::Exception &e)
	{
		cout << e.getErrorString() << endl;
		close();
	}


	return 0;
}
예제 #2
0
int main()
{
	try{
		RCF::init();
	
		RCF::RcfServer server;
		server.addEndpoint(RCF::TcpEndpoint("0.0.0.0", 50001));
		server.addEndpoint(RCF::TcpEndpoint("::0", 50001));
		HelloWorld helloWorld;
		server.bind<I_HelloWorld>(helloWorld);
		server.start();

		RcfClient<I_HelloWorld> client(RCF::TcpEndpoint(50001));
		//client.getClientStub().connect(); // 如果不调用connect() 实际连接会推迟到第一次接口调用
		
		client.Print("我是客户端1");

		// 客户端获取连接的socket
		RCF::TcpClientTransport &transport = dynamic_cast<RCF::TcpClientTransport &>(client.getClientStub().getTransport());
		cout << "客户端Socket: " << transport.getNativeHandle() << endl;
		
	}
	catch (RCF::Exception &e)
	{
		cout << e.getErrorString() << endl;
	}

	cout << "任意键退出..." << endl;
	cin.get();

	return 0;
}
예제 #3
0
    void runTests(
        RCF::RcfServer &server, 
        RCF::I_ClientTransport & clientTransport,
        int concurrencyCount, 
        unsigned int clientReps, 
        unsigned int maxDelayMs = 0)
    {
        // now try a more realistic load test

        boost::shared_ptr<util::ImmediateProfile> immmediateProfilePtr;

        // bind I_X
        X x;
        server.bind( (I_X*) 0, x);

        // bind I_Y to object factory
        RCF::ObjectFactoryServicePtr objectFactoryServicePtr( 
            new RCF::ObjectFactoryService(10, 60));

        objectFactoryServicePtr->bind( (I_Y*) 0,  (Y**) 0);
        server.addService( RCF::ServicePtr(objectFactoryServicePtr));

        server.start();

        ThreadGroup threadGroup;

        // calls to I_X
        {
            util::ImmediateProfile profile("load test: all clients making static object calls");
            for (int i=0; i<concurrencyCount; ++i)
            {
                threadGroup.push_back( ThreadPtr( new Thread( boost::bind(
                    clientLoadTest, 
                    boost::ref(clientTransport), 
                    clientReps, 
                    maxDelayMs))));
            }
            joinThreadGroup(threadGroup);
        }

        // calls to I_Y
        threadGroup.clear();
        {
            util::ImmediateProfile profile("load test: all clients making dynamic object calls");
            for (int i=0;i<concurrencyCount; ++i)
            {
                threadGroup.push_back( ThreadPtr( new Thread( boost::bind(
                    clientObjectLoadTest, 
                    boost::ref(clientTransport), 
                    clientReps, 
                    maxDelayMs))));
            }
            joinThreadGroup(threadGroup);
        }

        // mixed
        threadGroup.clear();
        {
            util::ImmediateProfile profile("load test: half/half clients making static/dynamic object calls");
            for (int i=0; i<concurrencyCount; ++i)
            {
                switch(i%2)
                {
                case 0: 
                    
                    threadGroup.push_back( ThreadPtr( new Thread( boost::bind(
                        clientLoadTest, 
                        boost::ref(clientTransport), 
                        clientReps, 
                        maxDelayMs)))); 
                    
                    break;

                case 1: 
                    
                    threadGroup.push_back( ThreadPtr( new Thread( boost::bind(
                        clientObjectLoadTest, 
                        boost::ref(clientTransport), 
                        clientReps, 
                        maxDelayMs)))); 
                    
                    break;

                default: 
                    
                    RCF_ASSERT(0);
                }
            }
            joinThreadGroup(threadGroup);
        }

        server.stop();
    }