Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}