Exemplo n.º 1
0
  /** 启动初始化,他确定网络中有多少个其它UDPBase和相关的信息 */
  public void initNet() throws UDPBaseException {
    try {
      mainThread = new SoleThread(this);

      localIP = InetAddress.getLocalHost().getHostAddress();
      int i = localIP.lastIndexOf('.');
      BROADCAST_ADDR = localIP.substring(0, i) + ".255";
      // System.out.println ("lip=="+localIP) ;
      // sendSocket = new DatagramSocket () ;
      // recvSocket = new MulticastSocket (RECV_PORT) ;
      recvSocket = new DatagramSocket(RECV_PORT);
      sendSocket = recvSocket;
      // recvAckSocket = new MulticastSocket (RECV_ACK_PORT) ;
      group = InetAddress.getByName(BROADCAST_ADDR);
      // recvSocket.joinGroup (group) ;
      // recvAckSocket.joinGroup (group) ;

      procMsgThd = new ProcMsgThd();
      procMsgThd.start();
      //
      mainThread.start();
    } catch (Exception e) {
      e.printStackTrace();
      throw new UDPBaseException("UDPBase init() error=\n" + e.toString());
    }
  }
Exemplo n.º 2
0
  public void initGroup() throws UDPBaseException {
    try {
      mainThread = new SoleThread(this);

      sendSocket = new DatagramSocket();
      recvSocket = new MulticastSocket(RECV_PORT);
      // recvAckSocket = new MulticastSocket (RECV_ACK_PORT) ;
      group = InetAddress.getByName(GROUP_BROADCAST_ADDR);
      ((MulticastSocket) recvSocket).joinGroup(group);
      // recvAckSocket.joinGroup (group) ;
      localIP = InetAddress.getLocalHost().getHostAddress();

      procMsgThd = new ProcMsgThd();
      procMsgThd.start();
      //
      mainThread.start();

      bGroup = true;
    } catch (Exception e) {
      e.printStackTrace();
      throw new UDPBaseException("UDPBase init() error=\n" + e.toString());
    }
  }
Exemplo n.º 3
0
  public void initVirtual(String virtualip) throws UDPBaseException {
    if (virtualip == null) {
      virtualip = "vip:" + System.currentTimeMillis();
    }
    try {
      mainThread = new SoleThread(this);

      sendSocket = new DatagramSocket();
      recvSocket = new MulticastSocket(RECV_PORT);
      // recvAckSocket = new MulticastSocket (RECV_ACK_PORT) ;
      group = InetAddress.getByName(GROUP_BROADCAST_ADDR);
      ((MulticastSocket) recvSocket).joinGroup(group);
      // recvAckSocket.joinGroup (group) ;
      localIP = virtualip;

      procMsgThd = new ProcMsgThd();
      procMsgThd.start();
      //
      mainThread.start();
    } catch (Exception e) {
      e.printStackTrace();
      throw new UDPBaseException("UDPBase init() error=\n" + e.toString());
    }
  }