2009-09-10 62 views
0

我是新来的.net远程处理,我做了几个示例应用程序上.net remoting.i可以很容易地 从服务器通过远程对象获取文件,但我不知道如何发送文件到服务器端,如果有可能通过接口意味着如何设计它。给我一些建议和链接,这对我来说是正确的方向远程文件传输

回答

1

要发送一个文件,您可以重复调用服务器上的一个方法,以块为单位给它一个文件块。像这样:

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

你必须实现这种行为。客户端读取文件并发送字节。服务器接收字节并写入文件。还有更多,但这是你需要做的基础。