title: Java listening on port
body: <p>We want to capture the data which comes to the system on port say 7777. </p>
  
  <pre><code>public static void main(String[] args) {
          try {
              final ServerSocket serverSocket = new ServerSocket(7777);
              new Thread("Device Listener") {
                  public void run() {
                      try {
                          System.out.println("Listener Running . . .");
                          Socket socket = null;
                          while ((socket = serverSocket.accept()) != null) {
                              System.out.println("| Incoming : "+ socket.toString());
                          }
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  };
              }.start();
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  </code></pre>
  
  <p>We have a device which sends data to the port 7777, which comes with a native windows application. The windows native application is receiving data which comes from that device. We have to receive that data on port 7777 through our java project. </p>
  
  <p>In the above code,</p>
  
  <ol>
  <li><p>The java server socket is created but no incoming connections are received from the  device.</p></li>
  <li><p>The java server socket is receiving connections from telnet command. </p></li>
  <li><p>The data format which is used by the device and the other native application may be different, but atleast it has to be connected from java server socket. is it correct?</p></li>
  <li><p>how to receive the data which is transmitted to port 7777.</p></li>
  </ol>
  
  <p>EDIT:</p>
  
  <p>Ok, the data is received with UDP socket. it is 68 in length. The device documentation doesn't specify any methods to capture this data, because may be it is designed to work with the specified application. We can't contact the manufacturer also. is there any way (if possible) to know the format of incoming bytes. we have tried network sniffers but we cant understand  the format.</p>