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. 如何解决python连接数据库编码问题(python传数据到mysql乱码)'ascii' codec can't encode _mysql_exceptions.OperationalError: (1366, "Incorrect string value:?

    首先描述下问题:  在使用python计算出结果后将结果插入到mysql过程中,报如下错误.原因很好定位就是编码的问题.那么到底是编码哪里出了问题了呢? 报错如上: 排查顺序: 第一:python的编 ...

  2. A Zero Flow Entry Expiration Timeout P4 Switch

    文章名称:A Zero Flow Entry Expiration Timeout P4 Switch 零流表项期满超时P4交换机 发表时间:2018 期刊来源:SOSR ABSTRACT (摘要) ...

  3. JDBC的编码步骤

    0.前提:拷贝数据库的驱动到构建路径中(classpath) 1.注册驱动 2.获取与数据库的链接 3.创建代表SQL语句的对象 4.执行SQL语句 5.如果是查询语句,需要遍历结果集 6.释放占用的 ...

  4. [转帖]Linux后端执行命令的方法

    Linux 后台执行命令的方法 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4241330&fromuid=212883 ...

  5. Windows下多线程编程(二)

    线程的分类 1.     有消息循环线程 MFC中有用户界面线程,从CWinThread派生出一个新的类作为UI线程类CUIThread,然后调用AfxBeginthread(RUNTIME_CLAS ...

  6. webgl 混合

    先上例子 <!doctype html> <html> <head> <meta charset="utf-8" /> <ti ...

  7. oracle-表空间剩余空间大小占比查询

    select tablespace_name, max_gb, used_gb, round(100 * used_gb / max_gb) pct_used from (select a.table ...

  8. spring 事务传播 never 当一个业务方法设置为never时候表示 不会加入任何事务中

  9. TCP协议 连接三次握手

    TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位,有6种标 ...

  10. 【设计模式】—— 备忘录模式Memento

    前言:[模式总览]——————————by xingoo 模式意图 这个模式主要是想通过一个对象来记录对象的某种状态,这样有利于在其他需要的场合进行恢复. 该模式还有跟多可以扩展的地方,比如可以记录多 ...