Ah, this is the book again. It's like there's an interactive diagram, uh ... The order of the message response seems to be different from my program.
In fact, the problem is not big, the operation instance, the console runs the file App.js open service:
var io=require (' Socket.io '). Listen (8080,{log:false}); Io.sockets.on (' Connection ', function (socket) {Socket.on (' msg ', function (data) {Console.log (data), if (data.state) {if (data.state== ' OK ') {socket.emit (' msg ', {' Me ': ' Very good '});} Else{socket.emit (' msg ', {other: ' That's ' all '});}} Else{socket.emit (' msg ', {me: ' That's None '})})
Then the browser opens the page index.html:
<! DOCTYPE html>
You can then see the corresponding response in both consoles, socket.io.js please download it on the website. Note the client's Console.log () statement is output on the browser side, and the server output is in the cmd window.
I'll change the example a little, let two events listen to each other to trigger a better understanding of the message delivery, the final picture:
Output order: {state: ' OK '}->{me: ' Very good '}->{connection: ' Good '}->{me: ' That's none '}-> ... And then loop. If the expression is wrong, welcome the great God.
Use of Socket.io in node. js (node. JS Development Walkthrough A case study)