Domanda

Sono nuovo a .net remoting, ho fatto alcune applicazioni di esempio su .net remoting.i posso facilmente ottenere un file dal server attraverso l'oggetto remoto ma non so come inviare un file sul lato server, se è possibile tramite un'interfaccia significa come progettarlo. Dammi alcuni suggerimenti e collegamenti, sarà utile per me guidare nella giusta direzione

È stato utile?

Soluzione

Per inviare un file, è possibile chiamare ripetutamente un metodo sul server per assegnargli il blocco pezzo per blocco. In questo modo:

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

Altri suggerimenti

È necessario implementare questo comportamento. Il client legge il file e invia i byte. Il server riceve i byte e scrive il file. C'è di più, ma questa è la base di ciò che dovrai fare.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top