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的更多相关文章

  1. 最后通牒!8月1日开始ios中国区下架全部无版号游戏

      据媒体报道,苹果早于7月8日就给中国游戏开发者发送邮件,要求游戏开发者必须在7月31日前提交游戏版号及相关文件,否则付费游戏将不可以在中国AppStore供应,8月1日期全部正式下架. ​   需 ...

  2. 第26月第22天 iOS瘦身之armv7 armv7s arm64选用 iOS crash

    1.iOS瘦身之armv7 armv7s arm64选用 机器对指令集的支持是向下兼容的,因此armv7的指令集是可以运行在iphone5S以上的,只是效率没那么高而已~ 但是由于苹果要求必须支持ar ...

  3. 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS

    一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...

  4. 2016年5月面试题(Unity&iOS)

    NGUI的DrawCall drawcall定义:对底层图形程序(比如:OpenGL ES)接口的调用,以在屏幕上画出东西. List在内存中连续的空间保存 List是线性直接存储类型 mipMap是 ...

  5. 6月10日-IOS应用-日记本

    嗯,经过这几天的学习,我的第一个IOS应用,日记本算是学习完毕了,下面写一篇日记,记录所学到的知识和需要继续学习的地方. 1,首先是ViewController,必须添加两个协议UITableView ...

  6. 第28月第22天 iOS动态库

    1. NIMSDK 在 5.1.0 版本之后已改为动态库,集成方式有所改变,若需要集成高于此版本的 SDK,只需要做以下步骤: 将下载的 SDK 拖动到 Targets -> General - ...

  7. 第18月第2天 ios博客

    1. github https://githuber.cn/search?language=Objective-C https://www.jianshu.com/u/815d10a4bdce htt ...

  8. 2018年12月25&26日

    小结:昨天因为整理课件,调代码耗费了大量时间,所以没来得及整理作业,这两天主要做的题目是关于树链剖分和线段树的,难度大约都是省选难度,毕竟只要涉及到树链剖分难度就肯定不低. 一. 完成的题目: 洛谷P ...

  9. 第2月第6天 iOS 运行时添加属性和方法

    http://blog.csdn.net/meegomeego/article/details/18356169 第一种:runtime.h里的方法 BOOL class_addProperty(Cl ...

随机推荐

  1. Codeforces Round #550 (Div. 3) E. Median String (模拟)

    Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. 关于T/G/M/K

    //扫盲贴 K, G, T,都是表数量,只是个数字,在不同的场合下表示的不同.在计算机行业中,这几个量可用来表示数据传输速度和容量,下面分别讨论,希望不了解的朋友不要被某知道上的误解了.如果有什么错误 ...

  3. python获取时间————前一天后一天前一小时后一小时前一分钟后一分钟

    获取当天日期 一: import time print(time.strftime("%Y-%m-%d")) #输出当前日期 2018-05-01 二: import dateti ...

  4. Scrum Meeting day 1

    第一次会议,在这一次的会议中,明确了任务目标,并将任务进行合理分配,并且规划了整个任务的初步计划. No_00:分工情况 姓名 分工   崔强      PM 杜正远 主力工程师 王嘉豪 主力工程师 ...

  5. 我的IT未来

    关于IT这个行业,我是持欣赏态度的,毕竟发展很快,对人们生活的改变也很大,所以,作为一个从事IT的人士,我很自豪. 读了刘先生的文章,我发现以前自己做的太少了,虽然偶尔也会吐血写程序,但还是太少了.以 ...

  6. Java编写准备数据源

    1.装饰设计模式 package com.itheima.ds; import java.sql.Array; import java.sql.Blob; import java.sql.Callab ...

  7. ElasticSearch 2 (30) - 信息聚合系列之条形图

    ElasticSearch 2 (30) - 信息聚合系列之条形图 摘要 版本 elasticsearch版本: elasticsearch-2.x 内容 聚合还有一个令人激动的特性就是能够十分容易地 ...

  8. Alpha冲刺——day4

    Alpha冲刺--day4 作业链接 Alpha冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602634 ...

  9. NetScaler 10.1的配置以及结合StoreFront的部署

    工作需要,所以英文+中文,绝壁不是装逼...(关于这点勿喷) This post will cover only the basics for getting NetScaler up and run ...

  10. Redis 通信协议简单研究

    1.Redis网络通信协议 Redis底层网络通信协议其实是通过TCP来完成的. 2.Redis通信协议 Redis的通信协议首先是以行来划分,每行以\r\n行结束.每一行都有一个消息头,消息头共分为 ...