Socket. emit ('action'); indicates that an action command is sent, which is a string and can be written as follows when receiving the command from the other end: socket. on ('action', function (){...});
Socket. emit ('action', data); indicates that an action command and data are sent. When receiving data from the other end, you can write it as follows: socket. on ('action', function (data ){...});
Socket. emit (action, arg1, arg2); indicates that an action command is sent and there are two other data. When receiving the data from the other end, you can write it as follows: socket. on ('action', function (arg1, arg2 ){...});
The emit method contains callback functions, such:
Socket. emit ('action', Data, function (arg1, arg2 ){...}); there is a callback function that can be called at the other end, and the other end can be written as follows: socket. on ('action', function (data, FN) {fn ('A', 'B ');});
The data above can contain 0 or more data, and the number of parameters in the function can be changed at the other end. The number and sequence of parameters in the function should be consistent with that in sending.
The above FN indicates the parameter passed by another end. It is a function. If you write FN ('A', 'B'), the callback function is executed. Multiple callbacks cannot be written for a single sending. Otherwise, only the last callback takes effect. The callback should be used as the last parameter.
Use of emit and on in socket. Io]