无法通过移动3g网络访问服务器发送事件 [英] Not able to access Server-Sent-Events over Mobile 3g Network

查看:110
本文介绍了无法通过移动3g网络访问服务器发送事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器发送事件有问题. 我的端点在移动3G网络上不可用.

I am having an issue with Server Sent events. My endpoint is not available on mobile 3G network.

我发现一个https端点(如下所示)在我的移动网络上可用.

One observation I have is that a https endpoint like the one below which is available on my mobile network.

https://s- dal5-nss-32.firebaseio.com/s1.json?ns=iot-switch&sse=true

但是在我的移动网络上,当使用nginx传递代理并通过http(不使用ssl)访问代理时,同一个端点不可用.

But the same endpoint when proxy passed using an nginx and accessed over http (without ssl) is not available on my mobile network.

http://aws.arpit.me/live/s1.json?ns = iot-switch& sse = true

这可在我的家庭/办公室宽带网络上使用.仅在我的移动3g网络上产生问题. 有任何想法可能会发生什么事吗?

This is available on my home/office broadband network though. Only creates an issue over my mobile 3g network. Any ideas what might be going on?

我读到移动网络使用了可能导致此问题的透明代理损坏.但这是通过HTTP进行的.

I read that mobile networks use broken transparent proxies that might be causing this. But this is over HTTP.

任何帮助将不胜感激.

推荐答案

我怀疑移动网络正在强制使用HTTP代理,该代理会在将文件转发到浏览器之前尝试缓冲文件.缓冲将使SSE消息在缓冲区中等待.

I suspect the mobile network is forcing use of an HTTP proxy that tries to buffer files before forwarding them to the browser. Buffering will make SSE messages wait in the buffer.

使用SSE,有一些技巧可以解决此类代理问题:

With SSE there are a few tricks to work around such proxies:

  • 发送消息后,关闭服务器上的连接.代理将观察文件"的末尾并转发其已缓存的所有消息.

  • Close the connection on the server after sending a message. Proxies will observe end of the "file" and forward all messages they've buffered.

这等效于长时间轮询,因此不是最佳选择.为避免降低所有客户端的性能,您只有在检测到必要时才可以执行此操作,例如当客户端连接时,总是发送欢迎消息.客户端应该收到该消息,如果消息没有很快到达,则通过AJAX请求将该问题报告给服务器.

This will be equivalent to long polling, so it's not optimal. To avoid reducing performance for all clients you could do it only if you detect it's necessary, e.g. when a client connects always send a welcome message. The client should expect that message and if the message doesn't arrive soon enough report the problem via an AJAX request to the server.

在消息之前或之后,在SSE注释中发送4至16KB的数据.某些代理的缓冲区大小有限,这会使缓冲区溢出,从而迫使消息输出.

Send between 4 and 16KB of data in SSE comments before or after a message. Some proxies have limited-size buffers, and this will overflow the buffer forcing messages out.

使用HTTPS.这会绕过所有第三方代理.如果可以使用HTTPS,那是最好的解决方案.

Use HTTPS. This bypasses all 3rd party proxies. It's the best solution if you can use HTTPS.

这篇关于无法通过移动3g网络访问服务器发送事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆