2-製作多人HTML5遊戲:WebSocket通信。 NodeJ教程指南



第2集有關使用Nodejs在HTML5中製作多人視頻遊戲。在本視頻中,我介紹了如何使用WebSocket庫socket.io進行伺服器-客戶端通信。

檢查我的遊戲:http://rainingchain.com/

下載代碼:http://rainingchain.com/tutorial/nodejs

上一集:https://youtu.be/PfSwUOBL1YQ
下集:https://youtu.be/_GioD4LpjMw

如有任何疑問,請在下面發表評論。 。

49 comments
  1. Can someone explain me why if my client browser page is open and I restart the server the first socket connection ignores everything beyond the callback of the connection itself. If I restart the server and then open the browser page of the client this doesn't happen.

  2. i do no get socket connection in my log

    only 2 differences i have is i have a dedicated log function
    and instead if saying function i just used the arrow function method

    function log(MESSAGE,ID='System',STATUS='OK'){
    console.log(`[${ID}][${STATUS}]:${MESSAGE}`)
    };

    var io = require('socket.io')(serv,{});
    io.sockets.on('connection',(socket)=>{
    log('socket connection');
    });

  3. simply doesn't work for me. even went and did the shitty thing and copy/pasted finalcode from the link in description. same errors, only more.
    lovely. got excited for nada

  4. not working for me once i put in the html scripts
    i'm getting errors in "after argument list" and starts listing off files in internal/modules/cjs/loader that i haven't even touched…

  5. After this tutorial I made chat application but was very disappointed with lag, I don't think it's problem in my code (I didn't try to do anything fancy). If websocket lags so much making realtime game is impossible…

  6. /root/server/node_modules/socket.io/node_modules/engine.io/node_modules/uws/uws.js:3
    const http = require('http');
    ^^^^^
    SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Server.init (/root/server/node_modules/socket.io/node_modules/engine.io/lib/server.js:115:16)
    at new Server (/root/server/node_modules/socket.io/node_modules/engine.io/lib/server.js:65:8)
    at Function.attach (/root/server/node_modules/socket.io/node_modules/engine.io/lib/engine.io.js:123:16)
    at Server.initEngine (/root/server/node_modules/socket.io/lib/index.js:274:21)

    When I'am launching the server

  7. Thank you so much for these tutorials. They are easy to follow and really helpful because I can't find any other tutorials anywhere that are what I want except this one. 😀

  8. I have the input code on index and App.js correct, it runs smooth and both node command prompt and Google chrome localhost, buuut…. it never says socket connection when I use Google chrome on the localhost.. Why is that? however the Server started statement does pop up

  9. A very useful tool for not restarting the server over and over again is the npm package "nodemon".
    It watches for file changes and if you save and reload the page the server restarts automatically.

  10. How can i add external css and js? All files (with index.htm)l are in client so i refer only to file like <script src="/main.js"></script> and console return error 404(not found) :<

Comments are closed.