问题
I'm using CloudFlare to implement a REST API. I need to add some notifications which are implemented with socket.io on Node.JS. When socket.io uses a live connection to keep client updated it will work because the connection is established between server-client, but what happens when socket.io does polling? Does CloudFlare use always the same server for each client?
回答1:
WebSockets are standardised by the IETF in RFC 6455, this allows you to avoid polling behaviour and instead directly maintain a bi-directional connection from the server to the client.
Whilst your existing stack (Node.js, Socket.io and CloudFlare) support polling behaviour; Socket.io can use WebSockets and CloudFlare now supports WebSockets!
WebSockets don't use traditional polling and instead act as a full-duplex communication protocol. When it is possible Socket.io will seek to use WebSockets when it can but fallback to polling when it can.
So what do you need to bear in mind? When using WebSockets be sure to use Ports that are acceptable to CloudFlare.
For requests made via HTTP/WS:
80
8080
8880
2052
2082
2086
2095
For requests made via HTTPS/WSS:
443
2053
2083
2087
2096
8443
There is an FAQ for using CloudFlare with WebSockets.
来源:https://stackoverflow.com/questions/38019656/cloudflare-and-socket-io