httping 支持发送fastopenfastpath请求吗

11548人阅读
【cocos2d-x】(35)
Cocos2d-x 3.2 Lua示例 XMLHttpRequestTest(Http网络请求)& & 本篇博客介绍Cocos2d-x 3.2Lua示例中的XMLHttpRequestTest,这里提供GET和POST两种http请求方式,返回数据类型有以下几种:cc.XMLHTTPREQUEST_RESPONSE_STRING = 0 &-- 返回字符串类型cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER = 1 -- 返回字节数组类型cc.XMLHTTPREQUEST_RESPONSE_BLOB & = 2 -- 返回二进制大对象类型cc.XMLHTTPREQUEST_RESPONSE_DOCUMENT = 3 -- 返回文档对象类型cc.XMLHTTPREQUEST_RESPONSE_JSON = 4 -- 返回JSON数据类型这些常量的定义可以到Cocos2dConstants.lua下找到。示例代码:--[[
=================
XMLHttpRequestTest.lua
=================
require(&json&)
local function XMLHttpRequestLayer()
local layer = cc.Layer:create()-- 创建层
local winSize = cc.Director:getInstance():getWinSize()-- 得到窗口大小
local margin = 40-- 间距
local space
= 35-- 宽度
local function init()
local label = cc.Label:createWithTTF(&XML Http Request Test&, s_arialPath, 28)-- 使用ttf文字格式的标签
label:setAnchorPoint(cc.p(0.5, 0.5))-- 设置锚点
label:setPosition(cc.p(winSize.width / 2, winSize.height - margin))-- 设置显示位置,宽度为屏幕的中间,高度为屏幕高度减去间距
layer:addChild(label, 0) -- 添加标签到层中
-- 显示返回码的标签
local labelStatusCode = cc.Label:createWithTTF(&HTTP Status Code&, s_markerFeltFontPath, 20)
labelStatusCode:setAnchorPoint(cc.p(0.5, 0.5))
labelStatusCode:setPosition(cc.p(winSize.width / 2,
winSize.height - margin - 6 * space))
layer:addChild(labelStatusCode)
local menuRequest = cc.Menu:create() -- 创建菜单
menuRequest:setPosition(cc.p(0,0))
layer:addChild(menuRequest) -- 添加菜单
local function onMenuGetClicked()
local xhr = cc.XMLHttpRequest:new() -- http请求
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_STRING -- 响应类型
xhr:open(&GET&, &http://httpbin.org/get&) -- 打开链接
-- 状态改变时调用
local function onReadyStateChange()
-- 显示状态文本
local statusString = &Http Status Code:&..xhr.statusText
labelStatusCode:setString(statusString)
print(xhr.response)
-- 注册脚本回调方法
xhr:registerScriptHandler(onReadyStateChange)
xhr:send() -- 发送请求
labelStatusCode:setString(&waiting...&)
-- 测试Get的标签
local labelGet
= cc.Label:createWithTTF(&Test Get&, s_arialPath, 22)
labelGet:setAnchorPoint(cc.p(0.5, 0.5))
local itemGet
cc.MenuItemLabel:create(labelGet) -- 菜单标签
itemGet:registerScriptTapHandler(onMenuGetClicked) -- 菜单点击事件
itemGet:setPosition(cc.p(winSize.width / 2, winSize.height - margin - space))
menuRequest:addChild(itemGet) -- 添加菜单项
local function onMenuPostClicked()
local xhr = cc.XMLHttpRequest:new() -- 新建一个XMLHttpRequest对象
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_STRING -- 相应类型为字符串
xhr:open(&POST&, &http://httpbin.org/post&)-- post方式
local function onReadyStateChange()
labelStatusCode:setString(&Http Status Code:&..xhr.statusText)
print(xhr.response)
-- 注册脚本方法回调
xhr:registerScriptHandler(onReadyStateChange)
xhr:send()-- 发送
labelStatusCode:setString(&waiting...&)
-- 测试Post的标签
local labelPost = cc.Label:createWithTTF(&Test Post&, s_arialPath, 22)
labelPost:setAnchorPoint(cc.p(0.5, 0.5)) -- 设置锚点
local itemPost =
cc.MenuItemLabel:create(labelPost) -- 设置菜单项标签
itemPost:registerScriptTapHandler(onMenuPostClicked) -- 注册菜单项点击回调方法
itemPost:setPosition(cc.p(winSize.width / 2, winSize.height - margin - 2 * space))
menuRequest:addChild(itemPost)
--Post Binary
local function onMenuPostBinaryClicked()
local xhr = cc.XMLHttpRequest:new()-- 新建一个XMLHttpRequest对象
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER --返回数据为字节流
xhr:open(&POST&, &http://httpbin.org/post&) -- 打开Socket
-- 状态改变时调用
local function onReadyStateChange()
local response
= xhr.response -- 获得返回数据
local size
= table.getn(response) -- 获得返回数据大小
local strInfo = &&
for i = 1,size do
if 0 == response[i] then
strInfo = strInfo..&\'\\0\'&
strInfo = strInfo..string.char(response[i])
labelStatusCode:setString(&Http Status Code:&..xhr.statusText)
print(strInfo)
-- 注册脚本方法回调
xhr:registerScriptHandler(onReadyStateChange)
xhr:send()-- 发送
labelStatusCode:setString(&waiting...&)
-- 测试使用Post请求方式发送字节流
local labelPostBinary = cc.Label:createWithTTF(&Test Post Binary&, s_arialPath, 22)
labelPostBinary:setAnchorPoint(cc.p(0.5, 0.5))
local itemPostBinary = cc.MenuItemLabel:create(labelPostBinary)
itemPostBinary:registerScriptTapHandler(onMenuPostBinaryClicked)
itemPostBinary:setPosition(cc.p(winSize.width / 2, winSize.height - margin - 3 * space))
menuRequest:addChild(itemPostBinary)
--Post Json
local function onMenuPostJsonClicked()
local xhr = cc.XMLHttpRequest:new() -- 新建一个XMLHttpRequest对象
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON -- json数据类型
xhr:open(&POST&, &http://httpbin.org/post&)-- POST方式
local function onReadyStateChange()
-- 显示状态码,成功显示200
labelStatusCode:setString(&Http Status Code:&..xhr.statusText)
local response
= xhr.response -- 获得响应数据
local output = json.decode(response,1) -- 解析json数据
table.foreach(output,function(i, v) print (i, v) end)
print(&headers are&)
table.foreach(output.headers,print)
-- 注册脚本方法回调
xhr:registerScriptHandler(onReadyStateChange)
xhr:send()-- 发送请求
labelStatusCode:setString(&waiting...&)
-- 测试使用POST方式发送json的标签
local labelPostJson = cc.Label:createWithTTF(&Test Post Json&, s_arialPath, 22)
labelPostJson:setAnchorPoint(cc.p(0.5, 0.5)) -- 锚点
local itemPostJson = cc.MenuItemLabel:create(labelPostJson) -- 菜单项标签
itemPostJson:registerScriptTapHandler(onMenuPostJsonClicked) -- 注册菜单项点击
itemPostJson:setPosition(cc.p(winSize.width / 2, winSize.height - margin - 4 * space))
menuRequest:addChild(itemPostJson)
-- 节点回调事件
local function onNodeEvent(eventName)
if &enter& == eventName then
-- 注册层的监听回调事件
layer:registerScriptHandler(onNodeEvent)
return layer
function XMLHttpRequestTestMain()
local scene = cc.Scene:create() -- 创建场景
scene:addChild(XMLHttpRequestLayer()) -- 添加层
scene:addChild(CreateBackMenuItem()) -- 添加返回菜单项,具体实现查看helper.lua文件
return scene
效果图如下:Test Get:Test Post:Test Post Binary:Test Post JSON:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3857038次
积分:37751
积分:37751
排名:第83名
原创:642篇
转载:81篇
评论:2555条
难度:中级
类型:技术教程
难度:初级
类型:实战教学
文章:27篇
阅读:56103
阅读:77612
阅读:52904
文章:14篇
阅读:305039
文章:11篇
阅读:163013
文章:10篇
阅读:75058
文章:13篇
阅读:36663
文章:13篇
阅读:386073
微信公众号:wwjblog
微信号:whatswwj
移动开发者狂热群:注明入群理由,里面有一群热爱分享的开发者
高品质课堂推荐:
(2)(1)(3)(3)(2)(3)(5)(9)(3)(6)(2)(2)(2)(8)(5)(10)(3)(2)(3)(4)(12)(1)(5)(5)(6)(7)(2)(13)(11)(11)(8)(14)(10)(16)(8)(15)(23)(13)(12)(12)(11)(17)(28)(18)(20)(8)(11)(20)(13)(14)(10)(23)(18)(15)(36)(27)(47)(16)(3)(28)(33)(14)(13)
从入门到成长到成熟再到优秀,大多数程序员走了前面一段相似的道路,而有些人却走得更远一些!!!!HTTP诊断工具 httping_Linux软件_Linux公社-Linux系统门户网站
你好,游客
HTTP诊断工具 httping
运行环境:
授权方式:BSD
软件大小:M
更新日期:
来源地址:
联系作者:Linux
httping 是一个用来测试 HTTP 请求的连接、发送请求、等待回应的时间。有点像 ping 这个网络工具,只不过它是针对 HTTP 服务器的。
相关资讯 & & &
& (05月17日)
& (02/05/:15)
& (04/18/:09)
& (02/05/:45)
& (05/10/:30)
& (04/05/:54)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款Nginx 1.5.8 发布, Listen指令支持fastopen参数_Linux新闻_Linux公社-Linux系统门户网站
你好,游客
Nginx 1.5.8 发布, Listen指令支持fastopen参数
来源:oschina.net&
作者:Linux
Nginx 1.5.8 发布了,下载地址:
(Linux/BSD) (Windows)
改进内容包括:
*) Feature: IPv6 support in resolver.*) Feature: the "listen" directive supports the "fastopen" parameter. (关于fastopen的介绍请看)*) Feature: SSL support in the ngx_http_uwsgi_module.*) Feature: vim syntax highlighting scripts were added to contrib.*) Bugfix: a timeout might occur while reading client request body in an SSL connection using chunked transfer encoding.*) Bugfix: the "master_process" directive did not work correctly in nginx/Windows.*) Bugfix: the "setfib" parameter of the "listen" directive might not work.*) Bugfix: in the ngx_http_spdy_module.
推荐阅读:
Nginx实现反向代理和负载均衡的配置及优化
Nginx做负载均衡报:nginx: [emerg] could not build the types_hash
Nginx 负载均衡模块 ngx_http_upstream_module 详述
Nginx+Firebug 让浏览器告诉你负载均衡将请求分到了哪台服务器
安装Nginx php5-fpm MySQL(LNMP环境搭建)
Nginx 的详细介绍:Nginx 的下载地址:
相关资讯 & & &
& (07月27日)
& (06月01日)
& (02月14日)
& (07月07日)
& (02月26日)
& (12/10/:17)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款TCP Fast Open 测试(1)_ IT技术精华
聚合国内IT技术精华文章,分享IT技术精华,帮助IT从业人士成长
>> 技术文章 >> 正文
TCP Fast Open 测试(1)
浏览: 11057 次
首先,这是一个未完成的测试。新闻上大家都知道,Nginx从1.5.8开始支持fastopen参数,Linux从3.5开始支持fastopen特性,并在3.10开始默认开启。httping是一个模拟ping输出的http请求客户端。从1.5开始支持发送fastopen请求,目前版本是2.3.4。我在 fedora 20 (内核3.13版) 上编译了 nginx 1.5.13,yum 安装了 httping 2.3.3版。开两个终端,一个运行tcpdump,然后另一个运行httping如下:httping -F -g .hk/url -c 1这时候看到前一个终端的输出是这样的:[chenlin.rao@com21-100 tfo]$ sudo tcpdump -i p5p1 -vvnxXs 0 tcp port 80tcpdump: listening on p5p1, link-type EN10MB (Ethernet), capture size 65535 bytes20:40:15.034486 IP (tos 0x0, ttl 64, id 52862, offset 0, flags [DF], proto TCP (6), length 147)
10.2.5.100.40699 & 74.125.128.199.http: Flags [S], cksum 0xbb34 (correct), seq :, win 29200, options [mss 1460,sackOK,TS val
ecr 0,nop,wscale 7,exp-tfo cookie 9a8e5a15f1deab96], length 750x0000:
ce7e 3c 0a02 0564
E....~@.@..&...d0x0010:
4a7d 80c7 9efb 0050 d78a a37c
J}.....P...|....0x0020:
d002 7210 bb34 b4 a
..r..4..........0x0030:
01da 6d02 03 0307 fe0c f989
..m.............0x0040:
9a8e 5a15 f1de ab96 2f 7572
..Z.....HEAD./ur0x0050:
6c20 f31 2e30 0d0a 486f 7374
l.HTTP/1.0..Host0x0060:
3a20 6f 6f67 6c65 2e63 6f6d
2e68 6b0d 0a55 67 656e 743a
.hk..User-Agent:0x0080:
69 6e67 2e 330d
.HTTPing.v2.3.3.0x0090:
...20:40:15.295644 IP (tos 0x0, ttl 30, id 42640, offset 0, flags [none], proto TCP (6), length 52)
74.125.128.199.http & 10.2.5.100.40699: Flags [S.], cksum 0x71c1 (correct), seq , ack , win 42900, options [mss 1430,nop,nop,sackOK,nop,wscale 6], length 00x0000:
1b8a 4a7d 80c7
E..4........J}..0x0010:
0a02 efb 6ff1 f0da d78a a37d
...d.P..o......}0x0020:
....q...........0x0030:
....20:40:15.295694 IP (tos 0x0, ttl 64, id 52863, offset 0, flags [DF], proto TCP (6), length 115)
10.2.5.100.40699 & 74.125.128.199.http: Flags [P.], cksum 0x5bf7 (correct), seq 1:76, ack 1, win 229, length 750x0000:
ce7f 5b 0a02 0564
E..s..@.@..[...d0x0010:
4a7d 80c7 9efb 0050 d78a a37d 6ff1 f0db
J}.....P...}o...0x0020:
5bf7 44 202f 7572
P...[...HEAD./ur0x0030:
6c20 f31 2e30 0d0a 486f 7374
l.HTTP/1.0..Host0x0040:
3a20 6f 6f67 6c65 2e63 6f6d
2e68 6b0d 0a55 67 656e 743a
.hk..User-Agent:0x0060:
69 6e67 2e 330d
.HTTPing.v2.3.3.0x0070:
...20:40:15.560807 IP (tos 0x0, ttl 30, id 42641, offset 0, flags [none], proto TCP (6), length 40)
74.125.128.199.http & 10.2.5.100.40699: Flags [.], cksum 0x5720 (correct), seq 1, ack 76, win 670, length 00x0000:
1b95 4a7d 80c7
E..(........J}..0x0010:
0a02 efb 6ff1 f0db d78a a3c8
...d.P..o.......0x0020:
20 00 0000
P...W.........20:40:15.568068 IP (tos 0x0, ttl 30, id 42642, offset 0, flags [none], proto TCP (6), length 269)
74.125.128.199.http & 10.2.5.100.40699: Flags [P.], cksum 0x85ae (correct), seq 1:230, ack 76, win 670, length 2290x0000:
1aaf 4a7d 80c7
E...........J}..0x0010:
0a02 efb 6ff1 f0db d78a a3c8
...d.P..o.......0x0020:
ae 50 2f31 2e30
P.......HTTP/1.00x0030:
.404.Not.Found..0x0040:
436f 6e74 656e 742d a20 7465
Content-Type:.te0x0050:
746d 6c3b 73 6574
xt/.charset0x0060:
0d0a a20 5765
=UTF-8..Date:.We0x0070:
642c 70 34 2031
d,.16.Apr.2014.10x0080:
0d 0a53 :15.GMT..Ser0x0090:
67 a 436f 6e74 656e
ver:.gws..Conten0x00a0:
742d 4c65 6e67
t-Length:.1428..0x00b0:
582d 72 6f74 f6e
X-XSS-Protection0x00c0:
3a20 313b 206d 6f64 653d 626c 6f63 6b0d
:.1;.mode=block.0x00d0:
.X-Frame-Options0x00e0:
4f52 d0a 416c
:.SAMEORIGIN..Al0x00f0:
ternate-Protocol0x0100:
:.80:quic....没错,在第一个 SYN 包的时候就把 HEAD 请求带过去了。但是发现比较奇怪的是很多时候一模一样的命令,SYN 包上就没带数据。按我的想法,既然还是第一个 SYN 包,客户端这边压根不知道服务器端的情况,那么应该不管服务器端如何 SYN 里都带有 HEAD 请求啊?另外,用 httping -F 命令测试自己编译的 nginx 的时候,一直都没看到正确的抓包结果,HEAD 请求一直都是在三次握手后发送的。试图用 systemtap 来追踪一些问题。第一步确认我的 nginx 的 socket 是不是真的开了 fastopen:一个终端运行如下命令:stap -e 'probe kernel.function("do_tcp_setsockopt") {printf("%dn", $optname)}'另一个终端启动nginx,看到前一个终端输出结果为23,查 tcp.h 可以看到 23 正是 TCP_FASTOPEN 没错!第二步确认 httping 发送的时候是不是开了 fastopen:一个终端运行如下命令:stap -e 'probe kernel.function("tcp_sendmsg") {printf("%d %xn",$msg-&msg_namelen,$msg-&msg_flags)}'另一个终端运行最开始提到的 httping -F 命令,看到前一个终端输出结果为 16 ,查 socket.h 可以看到 MSG_FASTOPEN 是 0x,MSG_DONTWAIT 是 0x40,也就是说 httping 也没问题。现在比较郁闷的一点是:在 net/ipv4/tcp.c 里,tcp_sendmsg() 函数会判断 if ((flags & MSG_FASTOPEN)),就调用 tcp_sendmsg_fastopen() 函数来处理。但是试图用 systemtap 来调查这个函数的时候,会报一个错:WARNING: probe kernel.function("tcp_sendmsg_fastopen@net/ipv4/tcp.c:1005") (address 0xffffffff815cca08) registration error (rc -22)原因还未知。留记,继续研究。注1:发现 chrome 即使在 about:flags 里启用了 fastopen 好像也不行,必须命令行 google-chrome --enable-tcp-fastopen 这样打开才行。注2:网上看到有人写server和client的demo演示fastopen,但其实不对,demo代码里print的数据是正常三次握手以后socket收到的。这点开tcpdump才能确认到底是什么时候发送的数据。2014 年 04 月 18 日更新:今天改用 wireshark 看了一下数据包,在第一个 SYN 包没有带请求数据的时候,其实最末尾可选项里是有 fastopen 的,截图如下。看来还是服务器端的问题。下一步研究 tcp_recvmsg() 函数去。
本页关键字

我要回帖

更多关于 ss fast open 的文章

 

随机推荐