node SOCKET.iO的使用方法

福尔摩斯对我笑 2019-01-18 7079 次 2099条

服务器发送,客户端监听

  • 服务端安装 socket.io
 cnpm install socket.io --save
  • 客户端安装scoket.io.js文件,去socket.io官网下载js文件
<script src="/static/js/socket.io.js"></script>
  • 书写服务端代码
//引入io并监听2000端口
const io = require('socket.io')(2000);

//向客户端发送数据
setInterval(function(){
socket.emit(`del_files`, 'xxxxxxxx');
console.log(1)
},1000)

  • 书写客户端代码
//同样监听2000端口
var sockets = io.connect('http://localhost:2000');

sockets.on('del_files', function (data) {
alert(data);
})

好了,就是这么简单

客户端发送,服务器端监听

  • 引入方式同上面一样,这里就不写了
  • 客户端发送数据
setInterval(function(){
    socket.emit('req_server_cn', '1' );
},10000)
  • 服务器端监听
  io.sockets.on('connection',  function (socket) 
        {
        
            socket.on(`req_server_cn`, (data)=>{
              console.log(data)
            });
        });
  ``

好了,也是这么简单

标签: 无

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 2099 条评论 1


  1. 오바마카지노

    Robert P. Arnett. 2009. “Casino Royale and Franchise Remix: James Bond as Superhero”.
    Film Criticism, Vol. 33, No. 3, pp. 1-16. Meadville, PA:
    Allegheny College. Richard Dyer. 1998. Stars. London, UK:
    British Film Institute. Drew Moniot. 1976. http://www.google.cl/url?sa=t&ct=res&cd=3&url=http%3A%2F%2Furicasino369.com&ei=4n07SIzEM4jqeZeb2dAN&usg=AFQjCNFMSOxDLef0-CrlQs5JCAaWjs_Zlw&sig2=p5RgiwjfvrtZlJ8k_GHx1A

    回复 2020年2月26日
  2. 오바마카지노

    Robert P. Arnett. 2009. “Casino Royale and Franchise Remix: James Bond as Superhero”.
    Film Criticism, Vol. 33, No. 3, pp. 1-16. Meadville, PA: Allegheny College.
    Richard Dyer. 1998. Stars. London, UK: British Film Institute.
    Drew Moniot. 1976. http://www.google.cl/url?sa=t&ct=res&cd=3&url=http%3A%2F%2Furicasino369.com&ei=4n07SIzEM4jqeZeb2dAN&usg=AFQjCNFMSOxDLef0-CrlQs5JCAaWjs_Zlw&sig2=p5RgiwjfvrtZlJ8k_GHx1A

    回复 2020年2月26日
  3. w88

    Right here is the perfect web site for everyone who would like to understand this
    topic. You know a whole lot its almost hard to argue with you
    (not that I really would want to…HaHa). You certainly put a brand new spin on a
    topic which has been discussed for many years.

    Great stuff, just wonderful!

    回复 2020年2月26日
  4. hibiscus43.wordpress.com

    Thanks a lot for sharing this with all of us you really know what you are speaking approximately!
    Bookmarked. Kindly additionally consult with my website =).
    We can have a hyperlink alternate contract between us

    回复 2020年2月26日
  5. 태백출장맛사지카톡- Po 3 4『Poo3 4.c0M』출장코스가격출장만남Y⇠▦2019-03-07-11-39태백╗AIJ▦출장샵출장샵안내출장오쓰피걸ⓥ출장맛사지►출장여대생♧태백

    Greetings! Very useful advice within this post! It’s the little changes which will make the most important changes. Many thanks for sharing!

    回复 2020年2月26日
  6. qna.Nueracity.com

    I am sure this paragraph has touched all the internet visitors,
    its really really fastidious piece of writing on building
    up new webpage.

    回复 2020年2月26日
  7. viagra

    I was able to find good information from your blog posts.

    回复 2020年2月26日
  8. spillesider

    real vegas flash casino
    spil casino
    can you play keno online for money

    回复 2020年2月26日
  9. 샌즈 카지노

    I used to be recommended this web site via my cousin. I am now not certain whether or not this post is written by him as nobody else realize such specified approximately my trouble.

    You’re incredible! Thanks!

    回复 2020年2月26日
  10. cialis no prescription

    tadalafil ilacabak [url=http://www.buyscialisrx.com/]buy cialis online[/url] tadalafil 10mg online buy cialis
    online tadalafil topical tadalafil user reviews http://buyscialisrx.com/ what is the maximum
    dosage of tadalafil

    回复 2020年2月26日
  11. douche

    Very nice article. I certainly love this site. Continue the good work!

    回复 2020年2月26日
  12. Baltimore MD SEO

    After I originally commented I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve four emails with the same comment. There has to be a way you can remove me from that service? Kudos.

    回复 2020年2月26日
  13. shit

    The next time I read a blog, I hope that it doesn’t fail me as much as this particular one. I mean, Yes, it was my choice to read, however I really believed you would probably have something helpful to say. All I hear is a bunch of crying about something you could possibly fix if you were not too busy seeking attention.

    回复 2020年2月26日
  14. Zapatos Nike Outlet

    Everyone loves what you guys are usually up too.
    Such clever wrk and coverage! Keeep up the fantastic works guys I’ve included
    you guys to our blogroll.

    回复 2020年2月26日
  15. golden goose

    My wife and i got absolutely peaceful that Edward managed to conclude his homework from your ideas he gained through the blog. It is now and again perplexing to just choose to be handing out information that many other folks could have been making money from. We know we have the website owner to appreciate for that. The main explanations you’ve made, the simple web site menu, the friendships your site aid to create – it’s most great, and it’s really making our son in addition to our family know that the issue is thrilling, which is certainly wonderfully vital. Thanks for all!

    回复 2020年2月26日
  16. shit

    Having read this I believed it was really informative. I appreciate you taking the time and effort to put this short article together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worthwhile!

    回复 2020年2月26日
  17. asshole

    After I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I receive four emails with the exact same comment. Perhaps there is a way you are able to remove me from that service? Kudos!

    回复 2020年2月26日
  18. 더킹카지노

    As common, someone is sitting in our seats, to which I now make my second mistake of the day,
    I ask them to depart, I wish I hadn’t as a result of I’m now
    sat infront of the ‘Chav Squad’. http://breakthroughfilter.info/__media__/js/netsoltrademark.php?d=uricasino369.com&popup=1

    回复 2020年2月26日
  19. 더킹카지노

    As common, someone is sitting in our seats, to which I now make my second mistake of the day,
    I ask them to depart, I wish I hadn’t as a result of I’m now sat infront of
    the ‘Chav Squad’. http://breakthroughfilter.info/__media__/js/netsoltrademark.php?d=uricasino369.com&popup=1

    回复 2020年2月26日
  20. xxx free porn movies

    It’s appropriate time to make some plans for the future
    and it is time to be happy. I’ve read this post and if I could I
    desire to suggest you few interesting things or suggestions.
    Maybe you could write next articles referring to this article.
    I want to read more things about it!

    回复 2020年2月26日
  21. orgasm

    Great information. Lucky me I came across your blog by accident (stumbleupon). I have saved as a favorite for later!

    回复 2020年2月26日
  22. son of a bitch

    I used to be able to find good information from your content.

    回复 2020年2月26日
  23. son of a bitch

    Hello there! This post could not be written much better! Going through this post reminds me of my previous roommate! He always kept preaching about this. I am going to forward this article to him. Fairly certain he will have a very good read. Many thanks for sharing!

    回复 2020年2月26日
  24. Fuck off

    bookmarked!!, I love your website!

    回复 2020年2月26日
  25. tienda hippie low cost

    I want to show my appreciation to the writer just for bailing me out of this type of challenge. Right after checking throughout the internet and finding suggestions which were not powerful, I thought my entire life was done. Living minus the solutions to the difficulties you have sorted out all through your review is a critical case, and those which might have negatively damaged my entire career if I had not noticed your web site. Your own capability and kindness in controlling every item was precious. I’m not sure what I would have done if I hadn’t discovered such a point like this. I can also at this time relish my future. Thanks so much for the specialized and effective guide. I won’t be reluctant to suggest your site to anybody who needs to have recommendations about this problem.

    回复 2020年2月26日
  26. Electric Off Road Bikes

    I’ve read some just right stuff here. Certainly worth bookmarking for revisiting. I surprise how a lot attempt you put to create this kind of great informative web site.

    回复 2020年2月26日
  27. nba live stream free

    hi!,I love your writing so a lot! proportion we be in contact more approximately your post on AOL? I require a specialist on this space to solve my problem. Maybe that’s you! Taking a look forward to see you.

    回复 2020年2月26日
  28. xxx

    Everything is very open with a very clear clarification of the issues. It was really informative. Your site is useful. Many thanks for sharing!

    回复 2020年2月26日
  29. 슬롯 머신 게임

    Attractive portion of content. I simply stumbled upon your
    weblog and in accession capital to say that I get actually enjoyed account
    your weblog posts. Any way I’ll be subscribing to your augment or even I fulfillment you get admission to constantly quickly.

    回复 2020年2月26日
  30. Abbruch Abbruch

    Spot on with this write-up, I actually feel this site needs far more attention. I’ll probably be returning to read through more, thanks for the information!

    回复 2020年2月26日
  31. date

    Hi, I do believe this is a great blog. I stumbledupon it 😉 I may revisit once again since I bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to guide other people.

    回复 2020年2月26日
  32. Lexus888 Mobile version

    I’m not sure exactly why but this site is loading extremely slow for me.
    Is anyone else having this problem or is it a problem on my end?

    I’ll check back later and see if the problem still exists.

    回复 2020年2月26日
  33. Fuck off

    This is the perfect website for anyone who wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I really would want to…HaHa). You certainly put a brand new spin on a topic that has been discussed for decades. Excellent stuff, just great!

    回复 2020年2月26日
  34. 온라인바카라

    One of many nation’s finest-selling brands. Rolled at the
    legendary Camacho manufacturing facility, Baccarat
    is probably the greatest-promoting cigar brands
    within the US, that includes a candy tip head and mellow mix
    of Honduran tobaccos. http://cuisineaucoindufeu.xooit.fr/redirect1/http://uricasino369.com/

    回复 2020年2月26日
  35. 온라인바카라

    One of many nation’s finest-selling brands.
    Rolled at the legendary Camacho manufacturing facility,
    Baccarat is probably the greatest-promoting cigar brands within the US, that includes a candy tip head and mellow
    mix of Honduran tobaccos. http://cuisineaucoindufeu.xooit.fr/redirect1/http://uricasino369.com/

    回复 2020年2月26日
  36. Raleigh NC

    Everything is very open with a precise description of the issues. It was definitely informative. Your website is useful. Many thanks for sharing.

    回复 2020年2月26日
  37. suck

    bookmarked!!, I really like your blog!

    回复 2020年2月26日
  38. 에스엠 카지노

    Hi! I just wish to give you a big thumbs up for the excellent info you’ve got
    here on this post. I will be returning to your site for more soon.

    回复 2020年2月26日
  39. f2280 tc bolts

    I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to create my own blog and would like to know where u got this from. many thanks

    回复 2020年2月26日
  40. cara daftar main sbobet

    saw on kare11. tone-deaf…

    回复 2020年2月26日
  41. 온라인 바카라

    Hello! This is my 1st comment here so I just wanted to give a quick shout out and tell you I really enjoy reading your posts.
    Can you recommend any other blogs/websites/forums that deal with the same subjects?
    Thanks a lot!

    回复 2020年2月26日
  42. fag

    This page certainly has all the information I needed concerning this subject and didn’t know who to ask.

    回复 2020年2月26日
  43. 온라인 바카라

    I need to to thank you for this great read!! I definitely
    enjoyed every little bit of it. I’ve got you bookmarked to look at
    new stuff you post…

    回复 2020年2月26日
  44. nigger

    I used to be able to find good advice from your articles.

    回复 2020年2月26日
  45. ataşEhir escort

    Hello this is somewhat of off topkc bbut I was wanting to know if blogs uuse WYSIWYG editors or if you have to manually code
    with HTML. I’m starting a blog soon but have no coding skiills so I wanted
    to get guidance feom someone witrh experience.
    Any help would be greatly appreciated!

    回复 2020年2月26日
  46. cialis from canada

    hey there and thank you for your info – I’ve certainly picked up
    something new from right here. I did however expertise some technical issues using this site, as I experienced to reload the site many times previous to I
    could get it to load correctly. I had been wondering if your
    web hosting is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect
    your placement in google and can damage your high-quality score if ads
    and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for a lot more of your respective fascinating content.
    Ensure that you update this again soon.

    回复 2020年2月25日
  47. 온라인 바카라

    Thanks a lot for sharing this with all people you actually understand what you are speaking approximately!
    Bookmarked. Kindly also consult with my website =). We could have a link alternate contract among us

    回复 2020年2月25日
  48. penis

    After looking into a handful of the blog posts on your site, I honestly like your way of blogging. I saved as a favorite it to my bookmark website list and will be checking back soon. Please visit my web site too and let me know how you feel.

    回复 2020年2月25日
  49. engraving,

    Hi, I do think this is an excellent web site.
    I stumbledupon it 😉 I’m going to return yet again since I saved
    as a favorite it. Money and freedom is the best
    way to change, may you be rich and continue to help others.

    回复 2020年2月25日