public int receiveFromDataSocket(byte[] buf){
  int bytesRead;
  if (dataSocket == null) {
    Log.i(TAG,"Can't receive from null dataSocket");
    return -2;
  }
  if (!dataSocket.isConnected()) {
    Log.i(TAG,"Can't receive from unconnected socket");
    return -2;
  }
  InputStream in;
  try {
    in=dataSocket.getInputStream();
    while ((bytesRead=in.read(buf,0,buf.length)) == 0) {
    }
    if (bytesRead == -1) {
      return -1;
    }
  }
 catch (  IOException e) {
    Log.i(TAG,"Error reading data socket");
    return 0;
  }
  localDataSocket.reportTraffic(bytesRead);
  return bytesRead;
}

public int receiveFromDataSocket ( byte [ ] buf ) { int bytesRead ; if ( dataSocket == null ) { Log . i ( TAG , "Can't receive from null dataSocket" ) ; return - 2 ; } if ( ! dataSocket . isConnected ( ) ) { Log . i ( TAG , "Can't receive from unconnected socket" ) ; return - 2 ; } InputStream in ; try { in = dataSocket . getInputStream ( ) ; while ( ( bytesRead = in . read ( buf , 0 , buf . length ) ) == 0 ) { } if ( bytesRead == - 1 ) { return - 1 ; } } catch ( IOException e ) { Log . i ( TAG , "Error reading data socket" ) ; return 0 ; } localDataSocket . reportTraffic ( bytesRead ) ; return bytesRead ; }
received some bytes from the data socket , which is assumed to already be connected . the bytes are placed in the given array , and the number of bytes successfully read is returned .
