远程处理中的文件传输

发布于 2024-08-04 13:39:49 字数 128 浏览 5 评论 0原文

我是 .net 远程处理的新手,我在 .net 远程处理上做了一些示例应用程序。我可以轻松地 通过远程对象从服务器获取文件,但我不知道如何将文件发送到服务器端,如果可以通过接口意味着如何设计它。给我一些建议和链接,这对我很有用朝正确的方向行驶

I'm new to .net remoting,i done few sample applications on .net remoting.i can easily
get a file from the server through the remote object but i dont know how to send a file to the server side ,if it is possible through a interface means how to design it.give me some suggestions and links ,it will be useful for me to drive in the right direction

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人练习一个人 2024-08-11 13:39:49

要发送文件,您可以重复调用服务器上的方法以逐块向其提供文件。像这样:

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

To send a file, you could repeatedly call a method on the server to give it the file chunk by chunk. Like this:

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();
Smile简单爱 2024-08-11 13:39:49

您必须实施此行为。客户端读取文件并发送字节。服务器接收字节并写入文件。还有更多内容,但这是您需要做的基础知识。

You must implement this behavior. The client reads the file and sends the bytes. The server receives the bytes and writes the file. There is more to it, but that is the basics of what you will need to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文