0

こんにちは、Telnet 経由でファームウェア ファイルをモデム ボードに送信しようとしています。これが私のコードです:

    Socket s = null;
    try {
                SocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName(addr), 23);
                s = new Socket();
                s.connect(socketAddress, 1000);

        InputStream inputStream = s.getInputStream();
        OutputStream outputStream = s.getOutputStream();

        outputStream.write( (login + "\n") .getBytes());

        Thread.sleep(300);

        outputStream.write( (password + "\n") .getBytes());

        Thread.sleep(300);

                    outputStream.write(("swupdate" + "\n").getBytes());
                     Thread.sleep(300);                   

                      // Open the file that is the first
        // command line parameter
        FileInputStream fstream = new FileInputStream(path_frm_vdsl);
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line;
        // Read File Line By Line
        while ((line = br.readLine()) != null) {
            // Print the content on the console
            line = br.readLine();
            if (line == null) {
                Thread.sleep(1000);
            } else {
                //System.out.println(line);
                outputStream.write(line.getBytes());
                Log.v("---", line.getBytes() + "" + consumeInput(500, inputStream));
                //Log.v("Update_Modem","Updated " + consumeInput(500, inputStream));
                //outputStream.write(line.getBytes());
                Thread.sleep(10);
            }
        }

ログインして swupdate コマンドを送信し、ファームウェア ファイルをダンプして出力します。入力の最初の行の後、私は java.net.SocketException: Broken pipe を持っています そして、一度にすべてのファイルを読み取ることができず、十分なメモリ例外がありません。(3MB)

4

3 に答える 3

1

Telnet プロトコルの行末記号は \r\n です。

しかし、なぜファイル全体をメモリに読み込みたいのでしょうか? そして、なぜすべてが眠るのですか?そして、なぜ 2 行おきにスキップしているのですか? そして、consumeInput() とは何ですか?

バイトを読み書きするだけです。

于 2012-08-07T21:28:17.887 に答える
0

受信側がファームウェア、プレーンバイナリ、16進エンコード、base64エンコードをどのように望んでいるかわからない場合は、

とにかく、これがプレーンバイナリで送信する方法です

Socket s = null;
try {
    SocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName(addr), 23);
    s = new Socket();
    s.connect(socketAddress, 1000);

    InputStream inputStream = s.getInputStream();
    OutputStream outputStream = s.getOutputStream();

    outputStream.write((login + "\n").getBytes());

    Thread.sleep(300);

    outputStream.write((password + "\n").getBytes());

    Thread.sleep(300);

    outputStream.write(("swupdate" + "\n").getBytes());
    Thread.sleep(300);

    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream(path_frm_vdsl);
    byte[] buffer = new byte[1024];
    int fillSize;

    // Read File chunk by chunk
    while ((fillSize = fstream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, fillSize);
    }
    outputStream.close();
} finally {
    s.close();
}

したがって、データがなくなるまでファイルをチャンクで読み取り(readは-1を返します)、チャンクを書き込みます(readは実際に読み取られた量を返します)。

于 2012-08-07T22:07:49.237 に答える