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.