hamaXD

cliend lab2

Jan 31st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var net = require('net');
  2. var HOST = 'coc.waterphuket.com';
  3. var PORT = 6969;
  4. var client = new net.Socket();
  5. var i = 0;
  6. var answer = 3;
  7. end = () =>{
  8.     client.on('close', function() {
  9.         console.log('Connection closed');
  10.        });
  11. }
  12. send = () => {
  13.     client.on('data', function(data) {
  14.     console.log("DATA : " + data)
  15.         console.log("SEND : " + answer)
  16.         if(data=='OK'){
  17.         console.log("DATA : OK " )
  18.            client.write(''+answer);
  19.         }else if(data == 'WRONG'){
  20.             console.log("DATA : WRONG " )
  21.            client.write(''+answer);
  22.         }else if(data == 'BINGO'){
  23.            console.log("BINGO : " + answer)
  24.            client.destroy();
  25.            end()
  26.         }else if(data == 'END'){
  27.             client.destroy();
  28.         }
  29.         if(i==4){
  30.            client.destroy();
  31.            //connect()
  32.            setInterval(connect,5000)
  33.            i=0;
  34.         }
  35.         if(answer == 21){
  36.             answer = 0
  37.         }
  38.         answer++
  39.         i++
  40.        });
  41.        client.on('error' , (err) => "")
  42. }
  43.  
  44. connect = () =>{
  45.     client.connect(PORT, HOST, function() {
  46.         console.log('CONNECTED TO: ' + HOST + ':' + PORT);
  47.         client.write('5935512030');
  48.      });
  49.      send()
  50. }
  51. connect()
Advertisement
Add Comment
Please, Sign In to add comment