WebSockets(使用Socket.io)教程#5-广播消息



嗨,帮派,在此WebSockets教程中,我将向您展示如何向每个客户端广播消息,除了最初向服务器发送消息的客户端。这与从服务器发出消息相反,后者从服务器发出消息到每个单个客户端,包括最初发送消息的客户端。

—–课程链接:
+回购-https://github.com/iamshaunjp/websockets-playlist
+ Atom编辑器-https://atom.io/a
+下载节点-https://nodejs.org/en/
+ Socket.io-https://socket.io
————————————————– ——————————————-
相关教程:

—– NODE.JS教程

—–订阅频道-https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

==============网络忍者=====================

有关更多的前端开发教程并精通您的编码技能,请访问-https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg或http://thenetninja.co.uk

==================社交链接==================

Twitter-@TheNetNin​​ja-https://twitter.com/thenetninjauk

22 comments
  1. Another awesome tutorial from Shaun. When he has 10 million subscribers, I'll be able to say "I was watching him when he only had 300,000!" 🙂

  2. If you want to send chat by hitting the 'enter' key…

    let emitChat = function() {
    socket.emit('chat', {
    message: message.value,
    handle: handle.value
    });
    message.value = '';
    }

    // emit events

    btn.addEventListener('click', function() {
    emitChat();
    });

    message.addEventListener('keydown', function(event) {
    if (event.keyCode === 13) {
    emitChat();
    };
    });

  3. Thank you so much Net Ninja, is there any particular reason why you're still using old school javascript though? (non arrow functions/var)??

Comments are closed.