示例#1
0
  public void runTest() {
    try {
      pubnub.subscribe(
          "TestClientChannel",
          new Callback() {
            @Override
            public void successCallback(String channel, Object message) {
              recvSuccess++;
            }

            @Override
            public void errorCallback(String channel, PubnubError error) {
              recvErrors++;
            }
          });

    } catch (Exception e) {

    }
    Callback publishCb =
        new Callback() {
          @Override
          public void successCallback(String channel, Object message) {
            sendSuccess++;
          }

          @Override
          public void errorCallback(String channel, PubnubError error) {
            System.out.println(error.toString());
            sendErrors++;
          }
        };

    for (int i = 0; i < 10; i++) {
      pubnub.publish("TestClientChannel", "Test Client Message", publishCb);
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.out.println("Send Success : " + sendSuccess);
      System.out.println("Send Errors : " + sendErrors);
      System.out.println("Receive Success : " + recvSuccess);
      System.out.println("Receive Errors : " + recvErrors);
    }
    System.out.println("Send Success : " + sendSuccess);
    System.out.println("Send Errors : " + sendErrors);
    System.out.println("Receive Success : " + recvSuccess);
    System.out.println("Receive Errors : " + recvErrors);
  }
 private void subscribe(String channel) {
   try {
     mPubNub.subscribe(channel, this.mSubscribeReceiver);
   } catch (PubnubException e) {
     e.printStackTrace();
   }
 }