title: How to disconnect a websocket?
body: <p>I am using socket.io-client for connecting websocket</p>
  
  <pre><code>import socketIOClient from "socket.io-client";
  </code></pre>
  
  <p>After successfull api call i am opening a web socket and i can able to connect to socket and fetch the data, </p>
  
  <pre><code>_dashboardStoreChange(type){
    if (type == 'SingleDashboard') {
          let singledashboard = DashboardStore._getSingleDashboard() || {};
          this.setState({ singledashboard }, ()=&gt;{
            this.setState({
              dashboardName: this.state.singledashboard.data.dashboard_name,
             }, ()=&gt;{
              let ns = '/dashboard';
              let access_token = localStorage.getItem("auth_token");
              let user_id = localStorage.getItem("user_id")+ +new Date();
              let query_data = {access_token : access_token, user_id: user_id};
  
  
              const socket = socketIOClient('http://192.168.0.57:9000'+ns,{query:query_data});
              socket.on("dashboard_data", data =&gt; this.setState({ socketresponse: data }, ()=&gt;{
                localStorage.setItem("connected_socket_id", this.state.socketresponse.connected_socket_id);
              }));
  
  
  
              let chart_query_data = {"access_token":access_token, 'user_id' : user_id, dashboard_id: this.state.dashboard_id}
              socket.emit('fetch_graph_data', chart_query_data);
  
              socket.on('dashboard_data', data =&gt; this.setState({response: data}, ()=&gt;{
  
              }));
            });
  
          });
  
       }
  
  }
  </code></pre>
  
  <p>After socket connceted successfully i was trying to disconnect a socket from <code>componentWillUnmount</code> like below</p>
  
  <pre><code>  componentWillUnmount() {
      DashboardStore.removeListener('change', this._dashboardStoreChange);
      DataConnectionStore.removeListener('change', this._dataconnectionStoreChange);
  
  
      let ns = '/dashboard';
      let access_token = localStorage.getItem("auth_token");
      let user_id = localStorage.getItem("user_id")+ +new Date();
      let query_data = {access_token : access_token, user_id: user_id};
      const socket = socketIOClient('http://192.168.0.57:9000'+ns,{query:query_data});
  
  
      let disconnect_query_data = {access_token : access_token, user_id: user_id}
      socket.emit('disconnect_socket', disconnect_query_data);
  }
  </code></pre>
  
  <p>But as i am using again socket api another socket is geting opened, without calling the how can i disconnect.</p>
  
  <p>as in  <code>socket</code> variable using <code>socketIOClient</code> I am calling socket api.
  after componentwillunmount is called i need to disconnect the socket.</p>
  
  <p>Thanks in advance.</p>