CloudFlare和socket.io [英] CloudFlare and socket.io

查看:71
本文介绍了CloudFlare和socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CloudFlare来实现REST API.我需要添加一些通过Node.JS上的socket.io实现的通知.当socket.io使用实时连接来保持客户端更新时,它将起作用,因为该连接是在服务器-客户端之间建立的,但是当socket.io进行轮询时会发生什么呢?CloudFlare是否为每个客户端使用始终相同的服务器?

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?

推荐答案

WebSocket由IETF在 RFC中进行了标准化6455 ,这可以避免轮询行为,而直接维护从服务器到客户端的双向连接.

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.

现有堆栈(Node.js,Socket.io和CloudFlare)支持轮询行为;Socket.io可以使用WebSockets,并且 CloudFlare现在支持WebSockets

Whilst your existing stack (Node.js, Socket.io and CloudFlare) support polling behaviour; Socket.io can use WebSockets and CloudFlare now supports WebSockets!

WebSocket不使用传统的轮询,而是充当全双工通信协议.如果可能, Socket.io

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.

那么您需要牢记什么?使用WebSocket时,请确保使用CloudFlare可接受的端口.

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 

对于 查看全文

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