Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var packetTypes = {
- HEARTBEAT: 1,
- PLATFORM: 2
- };
- var platformTypes = {
- WIIU: 1,
- WII: 2,
- PC: 3
- };
- var time = 0;
- var clients = []
- var net=require("net");
- net.createServer(function(socket){
- socket.on("data",function(data){
- console.log(data);
- if(data[0] == packetTypes.HEARTBEAT){
- console.log("HEARTBEAT");
- var sendBuff = new Buffer([packetTypes.HEARTBEAT, time]);
- socket.write(sendBuff);
- } else if(data[0] == packetTypes.PLATFORM){
- if(data[1] == platformTypes.WIIU){
- pltfrm = "Wii U";
- } else if(data[1] == platformTypes.WII){
- pltfrm = "Wii";
- } else if(data[1] == platformTypes.PC){
- pltfrm = "PC";
- }
- console.log("Platform: " + pltfrm);
- }
- });
- socket.on("error",function(e){
- console.log("socket error:",e);
- socket.destroy();
- });
- socket.on("disconnect",function(){
- console.log("client sent disconnect event");
- socket.destroy();
- });
- socket.on("close",function(){
- console.log("socket closed");
- socket.destroy();
- });
- }).listen(11000);
Advertisement
Add Comment
Please, Sign In to add comment