2009-09-10 3 views
0

Je suis nouveau à .net remoting, j'ai fait quelques exemples d'applications sur .net remoting.i peut facilement obtenir un fichier du serveur à travers l'objet distant, mais je ne sais pas comment envoyer un fichier à la côté serveur, si c'est possible grâce à une interface signifie comment le concevoir.gif moi quelques suggestions et des liens, il sera utile pour moi de conduire dans la bonne directionFiletransfer à distance

Répondre

1

Pour envoyer un fichier, vous pouvez appeler à plusieurs reprises une méthode sur le serveur pour lui attribuer le fragment de fichier par tronçon. 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(); 
1

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, mais c'est la base de ce que vous devrez faire.