Not able to access Server-Sent-Events over Mobile 3g Network

落花浮王杯 提交于 2020-01-03 16:45:03

问题


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

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

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

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?

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

Any help would be appreciated.


回答1:


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.

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.

    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.

  • 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.

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



来源:https://stackoverflow.com/questions/30338366/not-able-to-access-server-sent-events-over-mobile-3g-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!