Question

Je suis nouveau dans le domaine .net remoting, j’ai pu créer quelques exemples d’applications sur .net remoting.i. obtenir un fichier du serveur via l'objet distant mais je ne sais pas comment envoyer un fichier côté serveur, si cela est possible via une interface signifie comment le concevoir. Donnez-moi des suggestions et des liens, cela me sera utile conduire dans la bonne direction

Était-ce utile?

La solution

Pour envoyer un fichier, vous pouvez appeler à plusieurs reprises une méthode sur le serveur afin de lui attribuer morceau par fichier. Comme ceci:

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

Autres conseils

Vous devez implémenter ce comportement. Le client lit le fichier et envoie les octets. Le serveur reçoit les octets et écrit le fichier. Il y a plus que cela, mais ce sont les bases de ce que vous devrez faire.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top