title: Streaming voice over tcp
body: <p>I've coded an app that streams audio over TCP from client to server but it does not work, i.e. no audible output. Could you check my code tell me whats wrong with it?</p>
  
  <p><strong>Client:</strong></p>
  
  <pre><code>public void startStreaming() {
  
  
     Thread streamThread = new Thread(new Runnable() {
  
         @Override
         public void run() {
              try {
  
                  int minBufSize =AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
  
                  Log.d("VD ", "Bufer intioalised "+minBufSize);
  
                  short[] buffer=new short[minBufSize];
  
  
                  Log.d("VS","Buffer created of size .c" + minBufSize);
                //  DatagramPacket packet;
  
                  final InetAddress destination = InetAddress.getByName(target.getText().toString());
                  port=Integer.parseInt(target_port.getText().toString());
  
                  Socket socket=new Socket(destination,port);
  
                  DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
                  Log.d("VS", "Address retrieved.c");
  
  
                  if (minBufSize != AudioRecord.ERROR_BAD_VALUE) {
                      recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,channelConfig,audioFormat,minBufSize);
                  Log.d("VS", "Recorder initialized.c");}
  
  
                  if (recorder.getState() == AudioRecord.STATE_INITIALIZED){
                      Log.d("VS", "Recorder working....c");
                      recorder.startRecording();}
  
                  BufferedWriter input;
                  while(status == true) {
  
  
                      //reading data from MIC into buffer
                    int  bufferReadResult = recorder.read(buffer, 0, buffer.length);
  
  
                        dos.write(buffer,0,bufferReadResult);
  
                    dos.flush();
  
  
  
                  }
  
              } catch(UnknownHostException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  Log.e("IOException message:",e.getMessage().toString());
  
  
              }
  
  
  
          }
  </code></pre>
  
  <p><strong>Server:</strong></p>
  
  <p>public void startStreaming() {
      Thread streamThread = new Thread(new Runnable() {</p>
  
  <pre><code>    @Override
      public void run() {
  
  
  
          try {
  
              int  minBufSize =1024;//recorder.getMinBufferSize(sampleRate,channelConfig,audioFormat);
  
  
              ServerSocket serversocket = new ServerSocket(50005);
  
  
  
               // DatagramSocket socket = new DatagramSocket(50005);
  
  
                byte[] buffer = new byte[1024];
  
  
                    if (minBufSize != AudioRecord.ERROR_BAD_VALUE) {
  
  
  
                        speaker = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,channelConfig,audioFormat,minBufSize,AudioTrack.MODE_STREAM);
  
  
                        speaker.play();
                        Log.d("VR", "spekaer playing...");
                    }
              //  }
  
  
  
  
                    Log.d("VR", ""+status);
                    BufferedReader input;
                    InputStream is;
                    ObjectInputStream ois;
                    ByteArrayInputStream baiss;
                    socket = serversocket.accept();
                      DataInputStream dis=new DataInputStream(new BufferedInputStream(socket.getInputStream()));
  
  
                          while(status == true) {
  
                                //DatagramPacket packet = new DatagramPacket(buffer,buffer.length);
  
                              InputStream in = socket.getInputStream();
  
                              Log.d("content :", socket.getOutputStream().toString());
  
  
                              int i=0;
                              while (dis.available() &gt; 0 &amp;&amp; i &lt; buffer.length) {
                                  buffer[i]=(byte) dis.readShort();
                                i++;
                              }
  
         speaker.write(buffer,0,buffer.length);
  </code></pre>
  
  <p>Please give me your best help.</p>