hi.

I'M developing a voice chat App stream voice over tcp protocol.

when client connects to server start Repeated beeps. too noisy...!no clear voice hearing... will you take a look at my code?

client :

PHP 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);
               // DatagramSocket socket = new DatagramSocket();
                byte[] buffer=new byte[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*=10);
                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);
                   
                 for (int i=0; i < bufferReadResult; i++) {
                      dos.write(buffer.toString().getBytes());
                      dos.flush();
                    }
                  
                    //packet = new DatagramPacket (buffer,buffer.length,destination,port);
                    
                   // socket.send(packet);
                    
             
                  // Log.d("", "wrote and "+buffer.toString().getBytes()+" socket: "+socket.getOutputStream());
             }
server :

PHP Code:
public void startStreaming() {
    Thread streamThread = new Thread(new Runnable() {

        @Override
        public void run() {
        	
        	 

        	  try {

                  int  minBufSize =640;//recorder.getMinBufferSize(sampleRate,channelConfig,audioFormat);


                 ServerSocket serversocket = new ServerSocket(50005);



                   // DatagramSocket socket = new DatagramSocket(50005);


                    byte[] buffer = new byte[640];


                        if (minBufSize != AudioRecord.ERROR_BAD_VALUE) {



                            speaker = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,channelConfig,audioFormat,minBufSize*=10,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() > 0 && i < buffer.length) {
                                      buffer[i]=(byte) dis.readShort();
                                    i++;
                                  }

                                  speaker.write(buffer,0,buffer.length);
	                              
	                             Log.d("VR", "Writing buffer content to speaker.s");
	                    }
	                        dis.close();

I'VE tried this with udp .do not suggest udp please