문제

.NET 리모 팅을 처음 접했는데 .NET 리모 팅에서 샘플 응용 프로그램이 거의 없었습니다. 원격 객체를 통해 서버에서 파일을 쉽게 가져올 수 있지만 가능하다면 파일을 서버쪽으로 보내는 방법을 모르겠습니다. 인터페이스를 통해 디자인하는 방법을 의미합니다. 몇 가지 제안과 링크를 작성하면 올바른 방향으로 운전하는 것이 유용합니다.

도움이 되었습니까?

해결책

파일을 보내려면 서버의 메소드를 반복해서 호출하여 파일 청크를 청크로 제공 할 수 있습니다. 이와 같이:

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