第7月第26天 iOS httpserver
1. cocoahttpserver
1)httpserver
[httpServer start:&error]
2)HTTPConnection
[newConnection start]
3)HTTPMessage HTTPResponse
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData*)data withTag:(long)tag
{
...
// Respond properly to HTTP 'GET' and 'HEAD' commands
httpResponse = [self httpResponseForMethod:method URI:uri];
if (httpResponse == nil)
{
[self handleResourceNotFound];
return;
}
[self sendResponseHeadersAndBody];
https://github.com/aldrinmartoq/brayatan/
https://github.com/robbiehanson/CocoaHTTPServer
2.poco
void TCPServerDispatcher::run()
{
AutoPtr<TCPServerDispatcher> guard(this, true); // ensure object stays alive int idleTime = (int) _pParams->getThreadIdleTime().totalMilliseconds(); for (;;)
{
AutoPtr<Notification> pNf = _queue.waitDequeueNotification(idleTime);
if (pNf)
{
TCPConnectionNotification* pCNf = dynamic_cast<TCPConnectionNotification*>(pNf.get());
if (pCNf)
{
std::auto_ptr<TCPServerConnection> pConnection(_pConnectionFactory->createConnection(pCNf->socket()));
poco_check_ptr(pConnection.get());
beginConnection();
pConnection->start();
endConnection();
}
} FastMutex::ScopedLock lock(_mutex);
if (_stopped || (_currentThreads > && _queue.empty()))
{
--_currentThreads;
break;
}
}
}
void HTTPServerConnection::run()
{
std::string server = _pParams->getSoftwareVersion();
HTTPServerSession session(socket(), _pParams);
while (!_stopped && session.hasMoreRequests())
{
try
{
Poco::FastMutex::ScopedLock lock(_mutex); if (!_stopped)
{
HTTPServerResponseImpl response(session);
HTTPServerRequestImpl request(response, session, _pParams); Poco::Timestamp now;
response.setDate(now);
response.setVersion(request.getVersion());
response.setKeepAlive(_pParams->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive());
if (!server.empty())
response.set("Server", server);
try
{
std::auto_ptr<HTTPRequestHandler> pHandler(_pFactory->createRequestHandler(request));
if (pHandler.get())
{
if (request.expectContinue())
response.sendContinue(); pHandler->handleRequest(request, response);
session.setKeepAlive(_pParams->getKeepAlive() && response.getKeepAlive() && session.canKeepAlive());
}
else sendErrorResponse(session, HTTPResponse::HTTP_NOT_IMPLEMENTED);
}
catch (Poco::Exception&)
{
if (!response.sent())
{
try
{
sendErrorResponse(session, HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
}
catch (...)
{
}
}
throw;
}
}
}
catch (NoMessageException&)
{
break;
}
catch (MessageException&)
{
sendErrorResponse(session, HTTPResponse::HTTP_BAD_REQUEST);
}
}
}
class TimeRequestHandler: public HTTPRequestHandler
/// Return a HTML document with the current date and time.
{
public:
TimeRequestHandler(const std::string& format):
_format(format)
{
} void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
app.logger().information("Request from " + request.clientAddress().toString()); Timestamp now;
std::string dt(DateTimeFormatter::format(now, _format)); response.setChunkedTransferEncoding(true);
response.setContentType("text/html"); std::ostream& ostr = response.send();
ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
ostr << dt;
ostr << "</p></body></html>";
} private:
std::string _format;
};
第7月第26天 iOS httpserver的更多相关文章
- 最后通牒!8月1日开始ios中国区下架全部无版号游戏
据媒体报道,苹果早于7月8日就给中国游戏开发者发送邮件,要求游戏开发者必须在7月31日前提交游戏版号及相关文件,否则付费游戏将不可以在中国AppStore供应,8月1日期全部正式下架. 需 ...
- 第26月第22天 iOS瘦身之armv7 armv7s arm64选用 iOS crash
1.iOS瘦身之armv7 armv7s arm64选用 机器对指令集的支持是向下兼容的,因此armv7的指令集是可以运行在iphone5S以上的,只是效率没那么高而已~ 但是由于苹果要求必须支持ar ...
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- 2016年5月面试题(Unity&iOS)
NGUI的DrawCall drawcall定义:对底层图形程序(比如:OpenGL ES)接口的调用,以在屏幕上画出东西. List在内存中连续的空间保存 List是线性直接存储类型 mipMap是 ...
- 6月10日-IOS应用-日记本
嗯,经过这几天的学习,我的第一个IOS应用,日记本算是学习完毕了,下面写一篇日记,记录所学到的知识和需要继续学习的地方. 1,首先是ViewController,必须添加两个协议UITableView ...
- 第28月第22天 iOS动态库
1. NIMSDK 在 5.1.0 版本之后已改为动态库,集成方式有所改变,若需要集成高于此版本的 SDK,只需要做以下步骤: 将下载的 SDK 拖动到 Targets -> General - ...
- 第18月第2天 ios博客
1. github https://githuber.cn/search?language=Objective-C https://www.jianshu.com/u/815d10a4bdce htt ...
- 2018年12月25&26日
小结:昨天因为整理课件,调代码耗费了大量时间,所以没来得及整理作业,这两天主要做的题目是关于树链剖分和线段树的,难度大约都是省选难度,毕竟只要涉及到树链剖分难度就肯定不低. 一. 完成的题目: 洛谷P ...
- 第2月第6天 iOS 运行时添加属性和方法
http://blog.csdn.net/meegomeego/article/details/18356169 第一种:runtime.h里的方法 BOOL class_addProperty(Cl ...
随机推荐
- 11.19daily_scrum
本阶段的工作内容为测试并且撰写笔记本APP应用的测试报告,目的在于总结测试阶段的测试以及分析测试结果,描述系统是否符合需求,测试软件功能的完善性.除了音频界面还未完成,其他部分均已开始实现测试功能,具 ...
- 【MOOC EXP】Linux内核分析实验四报告
程涵 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 [使用库函数API和C代码中嵌入汇编代 ...
- c语言四则运算
#include<stdio.h>#define W 5main(){ int a,b,i=0,c,d,r=0; while(i<W) { i++; srand(time()); a ...
- 软件工程课程设计——第一个Spring
开发会议框架表格: 1.我们团队Reborn针对需求功能进行热烈的讨论会议,从功能的方面分析开发,结合在一起组合为App软件,再另外思考附加的功能性娱乐项目. 2.开发过程中,以表格的形式反思开发过程 ...
- 第二个spring冲刺总结
讨论成员:罗凯旋.罗林杰.吴伟锋.黎文衷 第二阶段总体是做到了四则运算的demo,,包括APP进入动画,以及界面的基本效果设计,还有能进行综合计算(选择题,可以 自动生成简单,容易,困难 三种难度 ...
- ElasticSearch 2 (23) - 语言处理系列之词根提取
ElasticSearch 2 (23) - 语言处理系列之词根提取 摘要 世界上大多数语言都是屈折变化的,意思是词语可以通过变形来表达不同的含义: 数(Number): fox, foxes 时态( ...
- alpha冲刺随笔(一)
项目Alpha冲刺(团队) Alpha冲刺第一天 姓名 学号 博客链接 何守成 031602408 http://www.cnblogs.com/heshoucheng/ 黄锦峰 031602411 ...
- Linux命令(九)比较文件差异 diff
diff 命令介绍 diff 命令的功能为逐行比较两个文本文件,列出其不同之处.对给出的文件进行系统的检查,并显示出两个文件中所有不同的行.如果 diff 命令后跟的是目录,则会对该目录中的同名文件进 ...
- Docker in Docker的安装 路不通
1. 先启动centos 镜像 然后 再docker cp文件 然后再执行安装报错 [root@CentOS75 ~]# docker run -it centos /bin/bash [root@1 ...
- linux虚拟机安装中出现的问题
当虚拟机加载镜像时,出现下面的错误: vmware 已将该虚拟机配置为使用 64 位客户机操作系统.但是,无法执行 64 位操作. 错误提示:已将该虚拟机配置为使用 64 位客户机操作系统.但是,无法 ...