Socket.io 1.x Migration Guide

Source: Internet
Author: User

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.

    • Log output

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.

    • Configuration

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.

    • Transmission mode

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.