Pergunta

Eu sou novo para aplicativos de exemplo alguns .net remoting, i feito em .net remoting.i pode facilmente obter um arquivo do servidor através do objeto remoto, mas eu não sei como enviar um arquivo para o lado do servidor, se é possível através de um meio de interface como projetar it.give me algumas sugestões e links, que será útil para mim para conduzir na direção certa

Foi útil?

Solução

Para enviar um arquivo, você pode repetidamente chamar um método no servidor para dar-lhe o pedaço de arquivo por pedaço. Como esta:

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();

Outras dicas

Você deve implementar esse comportamento. O cliente lê o arquivo e envia os bytes. O servidor recebe os bytes e grava o arquivo. Há mais do que isso, mas isso é o básico do que você precisa fazer.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top