同步操作将从 feimat/fastrpc 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
arpc_client_for_pc 为客户端使用
::google::protobuf::RpcChannel* client;
echo::EchoService_Stub::Stub* stub;
client = new RpcClient(2, "192.168.1.13", 8999, 5000); // 1:并发sock数 2:host 3:ip 4:超时时间
if (!((RpcClient*)client)->IsConnected()) {
delete client;
exit(0);
} else {
std::cout << "connect success\n";
}
((RpcClient*)client)->RegiExtProcesser(ext_processer, NULL); // 处理服务器主动推的消息
((RpcClient*)client)->RegiCloseHandler(close_handler, NULL); // 断开事件处理
stub = new echo::EchoService_Stub::Stub(client);
request->set_message("client_hello");
stub->Echo(NULL, request, response, callback); // 异步, callback为空则是同步
arpc_server 为服务器使用
class EchoServiceImpl : public echo::EchoService { // rpc 函数实现
virtual void Echo(::google::protobuf::RpcController* controller,
const ::echo::EchoRequest* request,
::echo::EchoResponse* response,
::google::protobuf::Closure* done) {
response->set_response(request->message()+" server_hello");
//RpcController* p_con = (RpcController*)controller;
//unsigned cli_flow = p_con->_cli_flow;
//CASyncSvr* svr = p_con->_svr;
//RpcServer::PushToClient(svr, cli_flow, response); // 这是服务器额外主动推消息
if (done) {
done->Run();
}
}
};
class MyHttpHandler : public HttpHandler { // 同时可处理http请求
public:
virtual void Init(CASyncSvr* svr) {}
virtual void OnRec(HttpRequest* request,
::google::protobuf::Closure done) {
CHttpParser ps = request->ps;
ps->parse_form_body();
std::string kk = ps->get_param("kk");
//string str_cmd = ps->get_object();
//string get_uri = ps->get_uri();
//std::stringstream ss;
//ss << "kk:" << kk << "
"
// << "cmd:" << str_cmd << "
"
// << "uri:" << get_uri << "
";
std::string content_type = "text/html";
std::string add_head = "Connection: keep-alive\r\n";
CHttpResponseMaker::make_string(kk,
request->response,
content_type,
add_head);
if (done) {
done->Run();
}
}
virtual void Finish(CASyncSvr* svr) {}
};
int close_handler(CASyncSvr* svr, unsigned cli_flow, void* param) {
//std::stringstream ss;
//ss << "svr_id:" << svr->_svr_id
// << " cli:" << cli_flow
// << " param:" << ((int)param) << "\n";
//printf(ss.str().c_str());
return 0;
}
int main(int argc, char *argv[])
{
RpcServer server("192.168.1.13", 8999);
RPCREGI_ONEP(server, EchoServiceImpl);
HTTPREGI(server, MyHttpHandler);
server.RegiClientCloseHandler(close_handler, NULL);
server.start();
return 0;
}
参考各自目录下的main.cpp即可
欢迎bugfix,有协程编程经验同学将其改进成协程的编程方式
OK
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。