title: Mac: How to determine what websockets are open?
body: <p>I am trying to connect to a websocket that a tomcat client has created.
  What I see is ws://localhost:8080/cs-webapp/ws but when I try to connect to it, I get a 302 error. Other questions/answers here are not applicable :(</p>
  
  <p>I am using the following command to get a list of open ports on my machine and what I see related to tomcat are:</p>
  
  <pre><code>sudo lsof -PiTCP -sTCP:LISTEN
  java      localhost:21179 (LISTEN)
  java      *:63862 (LISTEN)
  java      *:49190 (LISTEN)
  java      *:8080 (LISTEN)
  java       *:8009 (LISTEN)
  java       TCP localhost:8005 (LISTEN)
  java        TCP *:58083 (LISTEN)
  </code></pre>
  
  <p>Having the above information, is there a way to determine which is the websocket port and how to connect it?</p>
  
  <p>the code snippets that I have tried are:</p>
  
  <pre><code>#!/usr/bin/env node
  var WebSocketClient = require('websocket').client;
  
  var client = new WebSocketClient();
  
  client.on('connectFailed', function(error) {
      console.log('Connect Error: ' + error.toString());
  });
  
  client.on('connect', function(connection) {
      console.log('WebSocket Client Connected');
      connection.on('error', function(error) {
          console.log("Connection Error: " + error.toString());
      });
      connection.on('close', function() {
          console.log('echo-protocol Connection Closed');
      });
      connection.on('message', function(message) {
          if (message.type === 'utf8') {
              console.log("Received: '" + message.utf8Data + "'");
          }
      });
  });
  
  //client.connect('ws://localhost:8080/cs-webapp/ws', 'echo-protocol');
  client.connect('ws://localhost:63862', 'echo-protocol');
  //client.connect('ws://localhost:8080/cs-webapp/ws', 'echo-protocol');
  </code></pre>