Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何关闭这个socket #28

Open
nejinn opened this issue Apr 2, 2020 · 0 comments
Open

如何关闭这个socket #28

nejinn opened this issue Apr 2, 2020 · 0 comments

Comments

@nejinn
Copy link

nejinn commented Apr 2, 2020

如何关闭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();
      }
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant