lhttp icon indicating copy to clipboard operation
lhttp copied to clipboard

如何关闭这个socket

Open nejinn opened this issue 4 years ago • 0 comments

如何关闭socket

    initLHTTP() {
      this.lHttpClient = new Lhttp("ws://127.0.0.1:9527");
      console.log(this.lHttpClient);
    },
    lHTTPOnOpen() {
      if (this.visible === true) {
        this.lHttpClient.on_open = function(context) {
          context.subscribe("test", "", null, "");
        };
      } else {
        this.lHttpClient.conn.close();
      }
    },
    lHTTPOnMessage() {
      this.lHttpClient.on_message = function(context) {
        if (context.getBody() !== "") {
          const lhttpData = JSON.parse(context.getBody().split("\r\n")[0]);
          console.log(lhttpData);
        }
      };
    },
    lHTTPOnError() {
      this.lHttpClient.on_error = function() {
        this.initLHTTP();
      };
    },
    lHTTPOnClose() {
      this.lHttpClient.on_close = function(context) {
        console.log("onclose:" + this.lHttpClient.conn + context);
        this.lHttpClient.conn.close();
      };
    },

这样写lHTTPOnClose不生效,我只能把close写到

    lHTTPOnOpen() {
      if (this.visible === true) {
        this.lHttpClient.on_open = function(context) {
          context.subscribe("test", "", null, "");
        };
      } else {
        this.lHttpClient.conn.close();
      }
    },

nejinn avatar Apr 02 '20 11:04 nejinn