keep-alive

HTTP 的长连接和短连接

拥有回忆 提交于 2020-01-08 06:55:19
一、什么是长连接 HTTP1.1规定了默认保持长连接(HTTP persistent connection ,也有翻译为持久连接),数据传输完成了保持TCP连接不断开(不发RST包、不四次握手),等待在同域名下继续用这个通道传输数据;相反的就是短连接。 HTTP首部的Connection: Keep-alive是HTTP1.0浏览器和服务器的实验性扩展,当前的HTTP1.1 RFC2616文档没有对它做说明,因为它所需要的功能已经默认开启,无须带着它,但是实践中可以发现,浏览器的报文请求都会带上它。如果HTTP1.1版本的HTTP请求报文不希望使用长连接,则要在HTTP请求报文首部加上Connection: close。《HTTP权威指南》提到,有部分古老的HTTP1.0 代理不理解Keep-alive,而导致长连接失效:客户端–>代理–>服务端,客户端带有Keep-alive,而代理不认识,于是将报文原封不动转给了服务端,服务端响应了Keep-alive,也被代理转发给了客户端,于是保持了“客户端–>代理”连接和“代理–>服务端”连接不关闭,但是,当客户端第发送第二次请求时,代理会认为当前连接不会有请求了,于是忽略了它,长连接失效。书上也介绍了解决方案:当发现HTTP版本为1.0时,就忽略Keep-alive,客户端就知道当前不该使用长连接。其实,在实际使用中不需要考虑这么多

HTTP长连接短连接

南楼画角 提交于 2020-01-08 04:47:38
一、什么是长连接 HTTP1.1规定了默认保持长连接(HTTP persistent connection ,也有翻译为持久连接),数据传输完成了保持TCP连接不断开(不发RST包、不四次握手),等待在同域名下继续用这个通道传输数据;相反的就是短连接。  HTTP首部的Connection: Keep-alive是HTTP1.0浏览器和服务器的实验性扩展,当前的HTTP1.1 RFC2616文档没有对它做说明,因为它所需要的功能已经默认开启,无须带着它,但是实践中可以发现,浏览器的报文请求都会带上它。如果HTTP1.1版本的HTTP请求报文不希望使用长连接,则要在HTTP请求报文首部加上Connection: close。《HTTP权威指南》提到,有部分古老的HTTP1.0 代理不理解Keep-alive,而导致长连接失效:客户端-->代理-->服务端,客户端带有Keep-alive,而代理不认识,于是将报文原封不动转给了服务端,服务端响应了Keep-alive,也被代理转发给了客户端,于是保持了“客户端-->代理”连接和“代理-->服务端”连接不关闭,但是,当客户端第发送第二次请求时,代理会认为当前连接不会有请求了,于是忽略了它,长连接失效。书上也介绍了解决方案:当发现HTTP版本为1.0时,就忽略Keep-alive,客户端就知道当前不该使用长连接。其实

另辟蹊径:vue单页面,多路由,前进刷新,后退不刷新

只谈情不闲聊 提交于 2020-01-08 01:58:52
另辟蹊径:vue单页面,多路由,前进刷新,后退不刷新 vue.js vue-cli vue-router javascript 阅读约 16 分钟 目的:vue-cli构建的vue单页面应用,某些特定的页面,实现前进刷新,后退不刷新,类似app般的用户体验。 注: 此处的刷新特指当进入此页面时,触发ajax请求,向服务器获取数据。不刷新特指当进入此页面时,不触发ajax请求,而是使用之前缓存的数据,以便减少服务器请求,用户体验更流畅。 项目需求: 任何技术的探索,都来自项目的需求。之前经手的一个项目是微信端商城,使用的是传统的mvc模式,利用的是jq+js,因此对于商城的项目需求比较熟悉。目前在学习vue,练手一个商城,遇到之前经常提及而无法很好解决的需求。有些页面需要前进刷新,后退不刷新。比如,从商城的【首页】-->【详情页】-->【订单提交页】,每次打开新页面都需要获取新数据,但是按下返回键后,就不需要再获取新数据了,而滚动条还保留在之前的位置。最常见的操作是从【首页】-->【详情页】,然后在从【详情页】-->【首页】,如此反复。 实例如图: 前人经验: 前人栽树,后人好乘凉。技术圈的分享一直都在蓬勃发展。遇到问题,我们可以尽情去搜索,去寻找大佬的足迹。针对上述需求,看到一个分享 vue-router 之 keep-alive ,比较符合我的需求,但是使用到我的项目上发现

vue的keep-alive

余生长醉 提交于 2020-01-07 15:52:23
keep-alive是vue的内置组件,能在组件切换过程中将状态保留在内存中,防止重复渲染DOM; keep-alive包裹动态组件的时候,会缓存不活动的组件实例,而不是销毁他们; <div> <!-- 当点击button时 组件one-name会根据status状态来切换 --> <span @click="button1" style="padding: 0 25px;">button</span><span @click="button2">button1</span> </div> <!-- include: 字符串或正则表达式。只有匹配的组件会被缓存 <keep-alive :include='OnetName'> 将会缓存组件名为OnetName的组件--> <!-- exclude: 字符串或正则表达式。任何匹配的组件都不会被缓存 <keep-alive :exclude='OnetName'> 将不会缓存组件名为OnetName的组件--> <keep-alive > <one-name v-if="status"></one-name> </keep-alive> 被keep-alive缓存的组件(当点击button按钮时 如果是被keep-alive缓存的组件则 "vue实例化" -> "dom渲染完毕",如果没有被缓存,则会一直 "vue实例化" ->

keep-alive遇见vue-router

依然范特西╮ 提交于 2020-01-06 21:38:52
保证组件活着 keep-alive是vue内置的一个组件,可以使被包含的组件保留状态,避免组件重新渲染,频繁创建销毁,router-view也是一个组件,如果直接被包在keep-alive里面,所有路径匹配到的视图组件都会被缓存 keep-alive有两个非常重要的属性 include -- 字符串或正则表达,只有匹配的组件才会被缓存 exclude --字符串或正则表达,任何匹配的组件都不会被缓存 <keep-alive exclude="profile,user"> <route-view/> </keep-alive> 这两个函数只有组件使用了keep-alive时才有效 activated(){ console.log("当前组件活跃") } deactivated(){ console.log("当前组件不活跃") } 来源: 51CTO 作者: 喝醉的熊 链接: https://blog.51cto.com/13550695/2464461

Session timeout when using signalr

蹲街弑〆低调 提交于 2020-01-03 17:32:14
问题 I have a web app that is used mainly for monitoring a system. It uses signalr to "server-push" updates from the server to refresh the display. The page also has some buttons which also uses the same signalr connection to send data to the server. The problem is signalr uses a separate connection so the session expires after the session timeout even when it is regularly sending and receiving data from the server. Is this the "correct" way to use signalr? Or should I just use signalr to inform

Reusing connections in Django with Python Requests

纵然是瞬间 提交于 2020-01-03 17:08:04
问题 What's the correct way of reusing Python Requests connections in Django across multiple HTTP requests. That's what I'm doing currently: import requests def do_request(data): return requests.get('http://foo.bar/', data=data, timeout=4) def my_view1(request) req = do_request({x: 1}) ... def my_view2(request) req = do_request({y: 2}) ... So, I have one function that makes the request. This function is called in various Django views. The views get called in separate HTTP requests by users. My

How do I keep a Perl script running on Unix after I log off?

南笙酒味 提交于 2020-01-01 19:26:06
问题 I have a script that takes a lot of time to complete. Instead of waiting for it to finish, I'd rather just log out and retrieve its output later on. I've tried; at -m -t 03030205 -f /path/to/./thescript.pl nohup /path/to/./thescript.pl & And I have also verified that the processes actually exist with ps and at -l depending on which scheduling syntax i used. Both these processes die when I exit out of the shell. Is there a way to keep a script from terminating when I close the connection? We

How to keep RTSP session alive?

ⅰ亾dé卋堺 提交于 2020-01-01 18:02:54
问题 I tried streaming on Google nexus S (2.3.7), HTC Desire (2.3.3), and Samsung Galaxy (3.2). And only Google Nexus has RTSP session timeout issue. I read up on some threads about this problem. It seems like I'll have to send RTCP request every second to keep the session alive, or I'll just send RTSP "OPTION" request which will basically do nothing but keep alive for my app. Could anyone give me a head start on how to generate that request? I have no experience dealing with RTCP before. 回答1:

How to set “Connection: keep-alive” header in lower case through HttpClient?

佐手、 提交于 2020-01-01 11:48:08
问题 I have a task where I need to be able to send Connection: keep-alive header the same way as it is done by the Firefox browser (notice that keep-alive has to be all lower-case): "Connection: keep-alive" However, I had no luck in achieving it using HttpClient. No matter what I try, the request always have "Connection: Keep-Alive" Here is an example code: var client = new HttpClient(); var request = new HttpRequestMessage() { RequestUri = new Uri("http://www.someURI.com"), Method = HttpMethod