Package net.sphene.goim.sniffudpconns

Source Code of net.sphene.goim.sniffudpconns.TestSniffUdpConns$NetStatThread

/*
* Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package net.sphene.goim.sniffudpconns;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import net.sphene.goim.netstat.NetStat;
import net.sphene.goim.netstat.NetStat.App;

public class TestSniffUdpConns {
  //UniqueIDs<String> uniqueIDs;
  Map<Integer, Object> apps;
  SniffUdpConns sniffUdpConns;

  public TestSniffUdpConns() {
    //uniqueIDs = new UniqueIDs<String>();
    sniffUdpConns = new SniffUdpConns();
  }
  public void go() {
    sniffUdpConns.startSniffing();
    NetStatThread netStatThread = new NetStatThread();
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    netStatThread.doRun();
    netStatThread.start();
  }
  /**
   * @param args
   */
  public static void main(String[] args) {
    new TestSniffUdpConns().go();
  }
 
  public void appsChanged(ArrayList<App> appList) {
    Map<Integer, Object> apps = new HashMap<Integer,Object>();
    int[][] conns = new int[appList.size()][6];
    int i = 0;
    for(App app : appList) {
      if(this.apps != null && !this.apps.containsKey(app.port)) {
        System.out.println("===== NEW BIND: " + app.port + ": " + app.path);
      }
      apps.put(app.port,app);
      conns[i][0] = app.a;
      conns[i][1] = app.b;
      conns[i][2] = app.c;
      conns[i][3] = app.d;
      conns[i][4] = app.port;
      conns[i][5] = app.port;
      i++;
    }
    TestSniffUdpConns.this.apps = apps;
    sniffUdpConns.setApps(apps,conns);
  }

  public class NetStatThread extends Thread {
    public void run() {
      while(true) {
        try {
          Thread.sleep(10000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        doRun();
      }
    }
    public void doRun() {
      System.out.println("Updating app list");
      NetStat netStat = new NetStat();
      netStat.getUdpPortsApps();
      appsChanged(netStat.appList);
    }
  }
}
TOP

Related Classes of net.sphene.goim.sniffudpconns.TestSniffUdpConns$NetStatThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.