title: Websocket closing after 60 seconds of being idle while connection node server using AWS ELB
body: <p>I have one node server running on EC2 instance and client is also running on same EC2 instance, Client open websocket connection to communicate node server, it is working in QA and Dev AWS environment but same web connection is getting close after 60 seconds of being idle in prod environment ,I am running client and node server behind ELB in aws environment.</p>
  <p>Client Code:</p>
  <pre><code>ws = new WebSocket('ws://localhost:8443');
          
  ws.onclose = function () {
      console.log(&quot;Websocket connection has been closed.&quot;);
      clientObj.emit('LogoffSuccess', 'LogoffSuccessfully');
  };
   
  ws.onerror=function(event)
  {
      console.log(event.data);
  };
              
  ws.addEventListener('open', function (event) {
      console.log('Websocket connection has been opened');
      ws.send(JSON.stringify(loginCreds));
  });
      
      
  </code></pre>
  <p>Node server Code below:</p>
  <pre><code>const wss = new WebSocket.Server({ server: app });
  const clients = {};
  const idMap = {};
      
  wss.on(`connection`, ws =&gt; {
    const headers = ws.upgradeReq.headers;
    const host = headers.host;
    const key = ws.upgradeReq.headers[`sec-websocket-key`];
      
    ctiServer.on(`responseMessage`, message =&gt; {
     clients[message.AgentId].send(JSON.stringify(message));
    });
      
    ws.on(`message`, message =&gt; {
      log.info(`Message received. Host: ${host}, Msg: ${message}`);
      if (JSON.parse(message).EventName === `Login`) {
        clients[JSON.parse(message).AgentId] = ws;
        idMap[key] = JSON.parse(message).AgentId;
       }
       ctiServer.processIncomingRequest(message);
    });
      
    ws.on(`close`, () =&gt; {
      log.info(`Connection closed. Host: ${host}`);
  
      const message = {
        EventName: `Logoff`,
        AgentId: idMap[key],
        EventData: {}
      };
          
   });
  });
  </code></pre>