title: Sending audio stream over TCP, UnsupportedAudioFileException
body: <p>I have succeeded with sending and reading text and images data over TCP sockets. But I am unable to sending and reading audio stream data.</p>
  
  <p>sample code at server:</p>
  
  <pre><code>public class ServerAudio {
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          try {
              ServerSocket serverSocker = new ServerSocket();
              Socket client = null;
              serverSocker.bind(new InetSocketAddress(6666));
              if (serverSocker.isBound()) {
                  client = serverSocker.accept();
                  OutputStream out = client.getOutputStream();
                  while (true) {
                      AudioInputStream ain = testPlay("C:/Users/Public/Music/Sample Music/adios.wav");
                      if (ain != null) {
                          AudioSystem.write(ain, AudioFileFormat.Type.WAVE, out);
                      }
                  }
              }
              serverSocker.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  
      public static AudioInputStream testPlay(String filename) {
          AudioInputStream din = null;
          try {
              File file = new File(filename);
              AudioInputStream in = AudioSystem.getAudioInputStream(file);
              System.out.println("Before :: " + in.available());
  
              AudioFormat baseFormat = in.getFormat();
              AudioFormat decodedFormat =
                      new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, baseFormat.getSampleRate(),
                              8, baseFormat.getChannels(), baseFormat.getChannels(),
                              baseFormat.getSampleRate(), false);
              din = AudioSystem.getAudioInputStream(decodedFormat, in);
              System.out.println("After :: " + din.available());
              return din;
          } catch (Exception e) {
              // Handle exception.
              e.printStackTrace();
          }
          return din;
      }
  }
  </code></pre>
  
  <p>sample code at client:</p>
  
  <pre><code>public class RDPPlayAudioBytes {
      private static Socket socket;
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          // SocketAddress socketAddress = new InetSocketAddress("172.19.1.50", 4444);
          try {
              Socket socket = new Socket("172.19.0.109", 6666);
              // socket.connect(socketAddress, 10000);
              if (socket != null &amp;&amp; socket.isConnected()) {
                  InputStream inputStream = socket.getInputStream();
                  // DataInputStream din=new DataInputStream(inputStream);
                  while (inputStream != null) {
                      if (inputStream.available() &gt; 0) {
                          System.out.println(inputStream.available());
                          InputStream bufferedIn = new BufferedInputStream(inputStream);
                          System.out.println("********** Buffred *********" + bufferedIn.available());
                          AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn);
                      }
                  }
              }
  
  
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } /*
             * catch (LineUnavailableException e) { // TODO Auto-generated catch block
             * e.printStackTrace(); }
             */catch (UnsupportedAudioFileException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Where I am getting Exception as</p>
  
  <pre><code>javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
      at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
  </code></pre>
  
  <p>Where I have observed that server is sending 35394bytes data to client, But at client side we are receiving 8192 bytes data. I am unable to understanding why bytes are missing at client side.</p>
  
  <p>Please help me how to send audio stream over TCP Sockets.</p>