Reprint Please specify: Theviper http://www.cnblogs.com/TheViper
Socket.io 1.x is updated from the end of May this year, from the version number to see, this is the second big update. See https://github.com/Automattic/socket.io/wiki/Migrating-to-1.0 for details. I'll just say a few things.
0.x version of the log output is directly in the terminal or command line output, the user can only control whether to output the log. In 1.x, the user can also specify what to output, for example, Debug=socket.io:socket node index.js can only output the socket object. You can specify that the output object is the Index,client,namespace,socket inside the./lib folder.
In addition, the log can be exported to the browser, see the Official Migration Guide.
Version 1.x this setting configures the
var socket = require (' Socket.io ') ({ // options gohere});
But for io.set(‘transports‘) ,,, io.set(‘heartbeat interval‘) io.set(‘heartbeat timeout‘io.set(‘resource‘),还是可以用0.x里的io.set()设置。
The following is not in the official migration guide, but I encountered during the migration process.
In 0.x, the transmission mode is WebSocket, Htmlfile, xhr-polling, Jsonp-polling,flash.
1.x is only polling and websocket!. You're right, there's only two of them. Polling merged the original xhr-polling, Jsonp-polling, and canceled the less commonly used and they feel inefficient and cost-effective htmlfile,flash.
The new version transfer is based on the Engine.io developed by the Socket.io team. This is from the source directory to see,
0.x
1.x
Engine.io is a higher level of abstraction for Socket.io, in the words of the author, the relationship between Engine.io and Socket.io is like the relationship between connect and express.
In addition, the 1.x version in the setting of the transmission mode, the equivalent of the egg pain.
0.x This setting allows you to specify the transfer mode.
Io.set (' transports ', [' xhr-polling ']); // [' WebSocket ', ' htmlfile ', ' xhr-polling ', ' jsonp-polling '] function (socket) { ...});
1.x inside this setting does not work, want to below so can.
function (socket) { io.set (' transports ', [ ' polling ' ]);});
- Emit to the specified socket
For example, to do a chat room private chat, one-on.
0.x
function (data, from, to) { var sid = Users[to]; Io.sockets.socket[sid].emit (' receive_msg ', { + ' says ' + data } ') ;
1.x
function (data, from, to) { var sid = Users[to]; Io.sockets.connected[sid].emit (' receive_msg ', { + ' says ' + data } ') ;
Temporarily encountered so much, later encountered new will update this article.
Socket.io 1.x Migration Guide