atm959

Server

Mar 17th, 2019
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var packetTypes = {
  2.     HEARTBEAT: 1,
  3.     PLATFORM: 2
  4. };
  5.  
  6. var platformTypes = {
  7.     WIIU: 1,
  8.     WII: 2,
  9.     PC: 3
  10. };
  11.  
  12. var time = 0;
  13.  
  14. var clients = []
  15.  
  16. var net=require("net");
  17. net.createServer(function(socket){
  18.     socket.on("data",function(data){
  19.         console.log(data);
  20.         if(data[0] == packetTypes.HEARTBEAT){
  21.             console.log("HEARTBEAT");
  22.             var sendBuff = new Buffer([packetTypes.HEARTBEAT, time]);
  23.             socket.write(sendBuff);
  24.         } else if(data[0] == packetTypes.PLATFORM){
  25.             if(data[1] == platformTypes.WIIU){
  26.                 pltfrm = "Wii U";
  27.             } else if(data[1] == platformTypes.WII){
  28.                 pltfrm = "Wii";
  29.             } else if(data[1] == platformTypes.PC){
  30.                 pltfrm = "PC";
  31.             }
  32.             console.log("Platform: " + pltfrm);
  33.         }
  34.     });
  35.    
  36.     socket.on("error",function(e){
  37.         console.log("socket error:",e);
  38.         socket.destroy();
  39.     });
  40.     socket.on("disconnect",function(){
  41.         console.log("client sent disconnect event");
  42.         socket.destroy();
  43.     });
  44.     socket.on("close",function(){
  45.         console.log("socket closed");
  46.         socket.destroy();
  47.     });
  48. }).listen(11000);
Advertisement
Add Comment
Please, Sign In to add comment