Пример #1
0
 public void startSearch() {
   Log.d(TAG, "Start search.");
   if (mStarted) {
     Log.d(TAG, "startSearch() ignore, search is already started.");
     return;
   }
   mStarted = true;
   NetWorkUtil.acquireWifiMultiCastLock(mContext);
   Thread searchThread = new Thread(this);
   searchThread.start();
 }
Пример #2
0
  public void stopSearch() {
    Log.d(TAG, "Stop search");
    mStarted = false;
    mStopped = true;
    leaveGroup(mMulticastAddress);
    NetWorkUtil.releaseWifiMultiCastLock();

    closeSocket();
    mInstance = null;
  }
Пример #3
0
    public void run() {
      DatagramPacket inPacket;

      while (!mStopped) {
        try {
          inPacket = new DatagramPacket(new byte[1024], 1024);
          mReceiveSocket.receive(inPacket);
          byte[] data = inPacket.getData();

          SearchProtocol.decodeSearchLan(data, mListener);
        } catch (Exception e) {
          if (e instanceof SocketTimeoutException) {
            // time out, search again.
            Log.d(TAG, "GetPacket time out. search again.");
          } else {
            Log.e(TAG, "GetPacket error," + e.toString());
            if (mListener != null) {
              mListener.onSearchStop();
            }
          }
        }
      }
    }