小于等于0.9版本 和 大于等于1.0版本差别
发布于 3 年前 作者 djGithub0727 2090 次浏览 来自 分享 过度到1.0以上版本和原有配置有些区别。特在此简单强调下:

1、Authentication differences (关于身份验证差异) uses middleware now
	  You can give a server arbitrary functions via io.use() that are run when a socket is created. Check out this example:
	  var srv = require('http').createServer();
	  var io = require('')(srv);
	  var run = 0;
	  io.use(function(socket, next){
		run++; // 0 -> 1
	  io.use(function(socket, next) {
		run++; // 1 -> 2
	  var socket = require('')();
	  socket.on('connect', function(){
		// run == 2 at this time
	  … so its cleaner to do auth via middleware now
	  The old io.set() and io.get() methods are deprecated and only supported for backwards compatibility. Here is a translation of an old authorization example into middleware-style.
	  io.set('authorization', function (handshakeData, callback) {    ** // <=0.9 版本方式**
		// make sure the handshake data looks good
		callback(null, true); // error first, 'authorized' boolean second 
	  io.use(function(socket, next) {        ** // >=1.0 版本方式**
		var handshakeData = socket.request;
		// make sure the handshake data looks good as before
		// if error do this:
		  // next(new Error('not authorized');
		// else just call next
	  Namespace authorization?
	  io.of('/namespace').use(function(socket, next) {
		var handshakeData = socket.request;

2、Configuration differences(配置差异)

	io.set is gone
	Instead do configuration in server initialization like this:
	var socket = require('')({
	  // options go here
	Options like log-level are gone. io.set('transports'), io.set('heartbeat interval'), io.set('heartbeat timeout', and io.set('resource') are still supported for backwards compatibility.
	Setting resource path
	The previous resource option is equivalent to the new path option, but needs a / in the beginning. For example, the following configuration
	var socket = io.connect('localhost:3000', {
	  'resource': 'path/to/';
	var socket = io.connect('localhost:3000', {
	  'path': '/path/to/';