WebSockets(使用Socket.io)教程#4-发出消息



嗨,帮派,在此网络套接字教程中,我将向您展示如何发出消息(均来自客户端和服务器),然后接收消息(均在客户端和服务器上)。这样,我们就可以开始充实我们的聊天应用程序了:)

—–课程链接:
+回购-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

43 comments
  1. I tried different tutorials to get into making servers with nodejs and I actually worked on nodejs servers in my previous job and this tutorial still opened my eyes for a lot of things. It is the first time I think I really understand how to do it.

  2. Never took the trouble to comment on a video before but dang. These videos are some other quality than any video I have ever seen, my compliments and keep up the good work!

  3. Made an account just to be able to comment. Amazing tutorial man! Great structure and good and easy to understand explanations. Quality Content! Keep it up man. Subscribed!

  4. Hi,
    I tried your code, now I am trying to deploy it, but it's not happening,
    I already made the io.connect('from localHost to deployed link')
    what to do any suggestions ??
    and please response asap.

  5. You are AMAZING! You're so good at explaining things, and I can't be thankful enough that you made this series available for free on YouTube!

  6. is it the best way? what if the link of socket.io changes or someone mess with it or put a virus in it? why not hard coding whatever is inside the socket.io.js into the browser? I assume nobody refers to a link in a real application

  7. It's weird but the thought comes to mind that a company was sold for $ 19.2B which essentially provides superior chat messaging experience and is based on a technology which in bare bones elementary level is as simple as this 14 min video.

  8. Sir …. I've successfully established the connection and all my codes on client as well as on server is same as yours … inspite of that I'm not able to display messages..
    Plzzz help me out

  9. Bro, I seriously appreciate your work. It has been awesome and thanks a lot. If only there were people who could explain as good as you.

  10. @4:35 not that it matters, but, after line 5 the rest of the variables are declared globally. The reason is because after the 'message' you closed it with a semicolon and the rest of them aren't declared with var, let, or const, so they are placed globally (as you know sean). But for this small app it doesn't really matter.

  11. Followed the same code and the button didn't work but did the following debug:
    1) Console.log inside the button worked
    2) Could Access the DOM.value content
    3) Considering those points the problema had to be in the socketio methods/functions
    4) I researched a little bit in the documentation of socket.io and what realized is they use "var socket = io();" instead of "var socket = io.connect('http://localhost/…);". With that change started working for me.Also changing in the server configuratio "io.socket.emit(…)" to "io.emit(…);" as most comments suggested.

  12. Man I was struggling so hard with all this socket data stuff and then i bumped into your tutorial. Thanks a lot you really explained it clearly here!

  13. For those who encountered a problem with a message not showing in the div, try to change the port number from 4000 to 4001 or something else, and type again in the cmder "nodemon index", worked for me

Comments are closed.