質問

.net remotingは初めてで、.net remoting.iで簡単にできるサンプルアプリケーションはほとんどありません。 リモートオブジェクトを介してサーバーからファイルを取得しますが、サーバー側にファイルを送信する方法がわからない正しい方向に運転する

役に立ちましたか?

解決

ファイルを送信するには、サーバー上のメソッドを繰り返し呼び出して、チャンクごとにファイルを指定します。このように:

static int CHUNK_SIZE = 4096;

// open the file
FileStream stream = File.OpenRead("path\to\file");

// send by chunks
byte[] data = new byte[CHUNK_SIZE];
int numBytesRead = CHUNK_SIZE;
while ((numBytesRead = stream.Read(data, 0, CHUNK_SIZE)) > 0)
{
    // resize the array if we read less than requested
    if (numBytesRead < CHUNK_SIZE)
        Array.Resize(data, numBytesRead);

    // pass the chunk to the server
    server.GiveNextChunk(data);
    // re-init the array so it's back to the original size and cleared out.
    data = new byte[CHUNK_SIZE];
}

// an example of how to let the server know the file is done so it can close
// the receiving stream on its end.
server.GiveNextChunk(null);

// close our stream too
stream.Close();

他のヒント

この動作を実装する必要があります。クライアントはファイルを読み取り、バイトを送信します。サーバーはバイトを受信し、ファイルを書き込みます。それだけではありませんが、それがあなたがする必要があることの基本です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top