【任务6】tf和cgi进行联合试验,完成日志服务器

改装gen-cpp目录下client.cpp文件

  • 代码如下:
#include "RecSys.h"
#include <iostream>
#include <string> #include <transport/TSocket.h>
#include <transport/TBufferTransports.h>
#include <protocol/TBinaryProtocol.h> #include <fcgi_stdio.h>
#include <fcgiapp.h> using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport; using namespace std;
using std::string;
using boost::shared_ptr; inline void send_response(
FCGX_Request& request, const std::string& resp_str) { FCGX_FPrintF(request.out, "Content-type: text/html;charset=utf-8\r\n\r\n");
FCGX_FPrintF(request.out, "%s", resp_str.c_str());
FCGX_Finish_r(&request);
} int main(int argc, char **argv){
// 1.初始化cgi
FCGX_Init();
FCGX_Request request;
FCGX_InitRequest(&request, 0, 0); // 2.连接connect server rpc
boost::shared_ptr<TSocket> socket(new TSocket("localhost",9090));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); transport->open(); RecSysClient client(protocol); while(FCGX_Accept_r(&request) >= 0) { // http page -> client
std::string send_data = FCGX_GetParam("QUERY_STRING", request.envp); string receive_data; // client >> server
// server >> client
client.rec_data(receive_data,send_data); cout << "receive http params: " << send_data << std::endl;
cout << "receive server data: " << receive_data << endl; /*send_response(request, return_str);*/
send_response(request, receive_data);
} transport->close();
return 0;
}

启动Nginx服务和gen-cpp目录下编译后的"server"

  • client.cpp文件代码修改为:
#include "RecSys.h"
#include <iostream>
#include <string> #include <transport/TSocket.h>
#include <transport/TBufferTransports.h>
#include <protocol/TBinaryProtocol.h> #include <fcgi_stdio.h>
#include <fcgiapp.h> using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport; using namespace std;
using std::string;
using boost::shared_ptr; inline void send_response(
FCGX_Request& request, const std::string& resp_str) { FCGX_FPrintF(request.out, "Content-type: text/html;charset=utf-8\r\n\r\n");
FCGX_FPrintF(request.out, "%s", resp_str.c_str());
FCGX_Finish_r(&request);
} int main(int argc, char **argv){
// 1.初始化cgi
FCGX_Init();
FCGX_Request request;
FCGX_InitRequest(&request, 0, 0); // 2.连接connect server rpc
boost::shared_ptr<TSocket> socket(new TSocket("localhost",9090));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); transport->open(); RecSysClient client(protocol); while(FCGX_Accept_r(&request) >= 0) { // http page -> client
std::string send_data = FCGX_GetParam("QUERY_STRING", request.envp); string receive_data; // client >> server
// server >> client
client.rec_data(receive_data,send_data); cout << "receive http params: " << send_data << std::endl;
cout << "receive server data: " << receive_data << endl; /*send_response(request, return_str);*/
send_response(request, receive_data);
} transport->close();
return 0;
}

Makefile 文件修改为

G++ = g++
CFLAGS = -g -Wall
INCLUDES = -I./ -I/usr/local/include/thrift
LIBS = -L/usr/local/lib/*.so -lthrift SER_OBJECT = RecSys.cpp RecSys_constants.cpp RecSys_types.cpp RecSys_server.skeleton.cpp
CLI_OBJECT = RecSys.cpp client.cpp server: $(SER_OBJECT)
$(G++) $(CFLAGS) $(INCLUDES) $(SER_OBJECT) $(LIBS) -o server client: $(CLI_OBJECT)
$(G++) $(CFLAGS) $(INCLUDES) $(CLI_OBJECT) $(LIBS) -o client .PHONY: clean
clean:
rm -f server client
  • 命令:make servermake clientmake clean等会对应执行名相应的命令

启动Nginx服务

  • 命令:安装目录/sbin/nginx
  • 检查端口是否开启:netstat -antup | grep nginx,端口为:80
  • 打开浏览器查看服务是否开启,查看

启动gen-cpp目录下的"server"

  • 命令:./server
  • 此时已经启动了cgi代理,查看端口是否监听成功:netstat -antup | grep 8088

启动cgi服务

  • 启动之前先编译client.cpp文件,命令:make client

  • 命令:/usr/local/src/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 8088 -f /test/thrift_test/python_thrift_demo/gen-cpp/client

查看整个流程的服务是否成功

  • 打开浏览器,查看,页面(也就是客户端)会返回server端输出的内容,同时server端会接收到客户端(也就是浏览器)发送的信息

  • 如图:

  • 带参数:

    • 客户端:

    • server端:

【六】tf和cgi进行联合试验,完成日志服务器的更多相关文章

  1. MySQL (六)--外键、联合查询、子查询

    1 外键 外键:foreign key,外面的键(键不在自己表中),如果一张表中有一个字段(非主键)指向另外一张表的主键,那么将该字段称为外键. 1.1 增加外键 外键可以在创建表的时候或创建表之后增 ...

  2. SQL语句(六)分页查询和联合查询

    目录 一.分页查询 语法格式 应用 二.联合查询 语法和作用 特点 应用 UNION和UNION ALL的区别 一.分页查询 语法格式 SELECT 查询列表 FROM 表 WHERE ... GRO ...

  3. Python的CGI编程实现-通过接口运行服务器py脚本

    yum 安装apcche [apache]yum 安装Apache(Centos 6.9) https://www.cnblogs.com/lauren1003/p/5993654.html只需一行命 ...

  4. 指定的 CGI 应用程序遇到错误,服务器终止了该进程。

    遇到这种错误只需要把这个项目的Cookies删除再重新启动就行了

  5. springboot学习入门简易版六---springboot2.0整合全局捕获异常及log4j日志(12-13)

    使用Aop实现 1创建异常请求 在原有项目基础上,jspController中创建一个可能发生异常的请求: /** * 全局捕获异常测试 * @param i * @return */ @Reques ...

  6. #企业项目实战 .Net Core + Vue/Angular 分库分表日志系统六 | 最终篇-通过AOP自动连接数据库-完成日志业务

    教程预览 01 | 前言 02 | 简单的分库分表设计 03 | 控制反转搭配简单业务 04 | 强化设计方案 05 | 完善业务自动创建数据库 06 | 最终篇-通过AOP自动连接数据库-完成日志业 ...

  7. Azure DevOps (六) 通过FTP上传流水线制品到Linux服务器

    上一篇我们实现了把流水线的制品保存到azure的流水线制品仓库里去,本篇我们会开始研究azure的发布流水线. 本篇要研究的是把流水线仓库的制品发布到任意一台公网的linux服务器上去,所以我们先研究 ...

  8. 第六章:Django 综合篇 - 14:Django 日志

    Django使用Python内置的logging模块实现它自己的日志系统. 如果你没有使用过logging模块,请参考Python教程中的相关章节. 直达链接<logging模块详解>. ...

  9. 【转】初识CGI

    一.基本原理 CGI:通用网关接口(Common Gateway Interface)是一个Web服务器主机提供信息服务的标准接口.通过CGI接口,Web服务器就能够获取客户端提交的信息,转交给服务器 ...

随机推荐

  1. Oracle replace()函数

    往Oracle 中导入数据时,有一个列导入的数据应该时‘2017-04-17’ 的格式,结果导入的数据为 ‘2017/04/17’格式的,1000多条记录要一条条改基本不可能. 于是想到了replac ...

  2. java获取文件大小的方法

    目前Java获取文件大小的方法有两种: 1.通过file的length()方法获取: 2.通过流式方法获取: 通过流式方法又有两种,分别是旧的java.io.*中FileInputStream的ava ...

  3. layui实现checkbox的目录树tree

    layui.use([ 'tree' ], function() {$ = layui.jquery;form = layui.form;//获取节点数据getTreeData();}); funct ...

  4. Current_Path 获取脚本所在路径(当前路径),取当前时间做文件名(uformat)

    获取脚本当前所在路径: $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.Las ...

  5. python笔记8-多线程threading之封装式

    执行函数 1.先写一个执行函数,用来实现做某件事情,不同的人吃火锅用一个参数people代替. # coding=utf-8 import threading import time def chiH ...

  6. HBase编程 API入门系列之create(管理端而言)(8)

    大家,若是看过我前期的这篇博客的话,则 HBase编程 API入门系列之put(客户端而言)(1) 就知道,在这篇博文里,我是在HBase Shell里创建HBase表的. 这里,我带领大家,学习更高 ...

  7. December 06th 2016 Week 50th Tuesday

    Behind every beautiful thing, there is some kind of pain. 美丽背后,必有努力. No pains, no gains. But it seem ...

  8. 关于数据库SQL优化

    1.数据库访问优化   要正确的优化SQL,我们需要快速定位能性的瓶颈点,也就是说快速找到我们SQL主要的开销在哪里?而大多数情况性能最慢的设备会是瓶颈点,如下载时网络速度可能会是瓶颈点,本地复制文件 ...

  9. TensorFlow函数(一)tf.placeholder()函数

    tf.placeholder(dtype, shape=None, name=None) 此函数用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.float32,tf ...

  10. Kali-linux使用Easy-Creds工具攻击无线网络

    Easy-Creds是一个菜单式的破解工具.该工具允许用户打开一个无线网卡,并能实现一个无线接入点攻击平台.Easy-Creds可以创建一个欺骗访问点,并作为一个中间人攻击类型运行,进而分析用户的数据 ...