コード例 #1
0
  /**
   * Store the msg if the websocket hasn't connected.
   *
   * @param msg
   */
  private void sendMsgs(String msg) {

    switch (state) {
      case NEW:
        {
          msges.add(msg);
          break;
        }

      case CONNECTED:
        {
          for (String sendMsg : msges) {
            wsc.sendTextMessage(sendMsg);
            LogCat.debug("send msg ====:" + msg);
          }

          msges.clear();
          wsc.sendTextMessage(msg);
          LogCat.debug("send msg ====:" + msg);
          break;
        }

      case CLOSED:
      case ERROR:
        {
          if (!wsc.isConnected()) {
            LogCat.e("the websocket isn't opening. you can't send any sth.");
            wsEvents.onError("the websocket isn't opening. you can't send any sth.");
            break;
          }
        }
    }
  }
コード例 #2
0
 @Override
 public void onOpen() {
   state = WebSocketState.CONNECTED;
   LogCat.debug("KWebSocket opened !");
   lockEvent = false;
   wsEvents.onConnected();
 }
コード例 #3
0
 @Override
 public void onTextMessage(final String s) {
   LogCat.debug("receive msg on Wschannnel***: " + s);
   checkvalidThreadMethod(
       new ValidThreadCall() {
         @Override
         public void onValidThread() {
           wsEvents.onMessage(s);
         }
       });
 }
コード例 #4
0
    @Override
    public void onClose(int webSocketCloseNotification, final String s) {
      state = WebSocketState.CLOSED;

      synchronized (waitLock) {
        lockEvent = true;
        waitLock.notify();
      }
      LogCat.debug("KWebSocke closed !");
      checkvalidThreadMethod(
          new ValidThreadCall() {
            @Override
            public void onValidThread() {
              wsEvents.onClosed(s);
            }
          });
    }