Websocket连接设置需要相当长的时间 - 这是正常吗? [英] Websocket connection setup takes a relatively long time - is this normal?
问题描述
当客户端和服务器都在本机上运行时,似乎需要大约1秒的时间来建立一个websocket连接。这对我来说好像很长一段时间了 - 是吗?有没有人可以和自己的经验比较?
详细信息:
我在客户端上有这样的websocket请求(Chrome 25,Windows 7 64):
ws = new WebSocket('ws://'+ host +':'+ port);
在服务器端我有Node ExpressJS 运行, einaros / ws 处理升级和WS连接。
我是在客户端上的时间,从新的 WebSocket()
到 ws.onopen
事件。
我发现这个问题有一个明确的答案。显然,使用 localhost
导致浏览器尝试连接到 ipv6
,然后回到 ipv4 1秒超时后,
使用 127.0.0.1
可以解决问题,因为它将首先尝试使用 ipv4
进行连接。 p>
It seems to be taking about 1 second to set up a websocket connection when the client and server are both running locally on my machine. This seems like quite a long time to me - is it? Could anyone compare this with their own experiences?
Details:
I have a websocket request like this on the client (Chrome 25, Windows7 64):
this.ws = new WebSocket('ws://' + host + ':' + port);
On the server side I have Node with ExpressJS running and einaros/ws handling the upgrade and WS connection.
I'm timing on the client, from just before the new WebSocket()
to the ws.onopen
event.
I found a clear answer to this question. Apparently, using localhost
causes the browser to try to connect to ipv6
first then fallback to ipv4
after a 1 second timeout. The problem is solved by using 127.0.0.1
because it will try to connect using ipv4
in the first place.
这篇关于Websocket连接设置需要相当长的时间 - 这是正常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!