0

I'm trying send encoded file from delphi to android via socket I'm using delphi xe4

here is my delphi code

procedure sendData();
begin
  dbdata = encodeFile('D:\data.sql');
  Memo1.Text := dbdata;
  ssMobile.Socket.Connections[cmbDevice.ItemIndex].SendText(dbdata + #10#13);
end;

and here is my android code

private void receiveFile() {
    try {
        BufferedReader input = new BufferedReader(new InputStreamReader(
                socket.getInputStream()));
        String read = input.readLine();
        if (!read.isEmpty()) {
            if (read.contains("enddb")){
                isFile = false;
            }
            byte[] dbAsBytes = read.getBytes();
            File filePath = new File(Environment.getExternalStorageDirectory()+"/data.sql");
            FileOutputStream os = new FileOutputStream(filePath, true);
            os.write(dbAsBytes);
            os.flush();
            os.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

here is my memo1.text

U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAAAAkAAAAAAAAAAAAAAAUAAAAEAAAAAAAAAAkA
AAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AC3iJw0PowAHBn8AD6cL+Q9u
C5cG1QtuBn8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

here is my received file

U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAAAAkAAAAAAAAAAAAAAAUAAAAEAAAAAAAAAAkA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAAAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAg

What's wrong with my code?? my received file is not same with my sent data??

mjn
  • 36,362
  • 28
  • 176
  • 378
  • What is the problem and what is your expected output? You are saying that something is wrong with your code but it is not obvious why you think it's wrong. – kkuilla Sep 19 '14 at 08:25
  • @kkuilla my received file is not same with my data sent – Ichwan Tofa Sep 19 '14 at 08:31
  • Did you check what is transmitted on the wire? Maybe it is a bug in you server socket component. I recommend to use Internet Direct (Indy) or Synapse. – mjn Sep 19 '14 at 10:14
  • Minor problem: why is the data followed by two line terminators? For readLine, both `\n` and `\r` terminate the line. – mjn Sep 19 '14 at 10:17

0 Answers0