使用套接字在网络中传输文件 [英] Transfer files in network with socket

查看:71
本文介绍了使用套接字在网络中传输文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用异步套接字服务器和客户端的写窗口服务将是Windows窗体。



http://msdn.microsoft.com/en-us/library/bew39x2a.aspx [ ^ ]



http://msdn.microsoft.com/en-us/library/fx6588te.aspx [<一个href =http://msdn.microsoft.com/en-us/library/fx6588te.aspxtarget =_ blanktitle =新窗口> ^ ]



在msdn中有例子,但是他们只是发送文本...我想发送和接收任何大小的文件...



我怎么能使用那个socket.sendfile和socket.beginsendfile方法....

i want write windows service that using asynchronous socket server and client side will be windows form.

http://msdn.microsoft.com/en-us/library/bew39x2a.aspx[^]

http://msdn.microsoft.com/en-us/library/fx6588te.aspx[^]

There are example in msdn but they just send text... I want send and recieve any size files...

How can i use that socket.sendfile and socket.beginsendfile methods....

推荐答案

你好,你的MSDN链接正确。如果您实现核心逻辑,您可以通过正确的套接字连接获取任意长度的文件。你必须将相应的文件转换为字节数组并通过套接字发送该文件。现在缓冲区大小是棘手的,你必须使用Redim或使用.net的Arraylist类(网上很容易获得的文章),所以你可以重用它们。

还有一件事你必须使用循环读取所有发送的文件字节直到缓冲区结束。将这些字节存储在一个目标字节数组(目标)中,然后在文件中转换这些字节。

现在我正忙着我的东西。如果我有时间我将尝试使用代码或链接从我的旧东西发布解决方案。

这一切都可以在互联网上轻松找到。

- 祝你好运
Hi,u got right msdn link. If u implement core logic u can get file of any length with proper socket connection. U have to convert respective file into byte array and send that file over socket. Now buffer size is tricky thing u have to use Redim or use Arraylist class of .net (easily available articles on net), so u can reuse them.
One more thing u have to use loop which will read all sent file bytes till end of buffer.Store these bytes in one target array of bytes (target),then convert this bytes in file.
Right now i m busy with my stuff.If i get time i will try to post solution with code or link from my old stuff.
This all things u can find easily on internet in parts.
-- Good luck


这篇关于使用套接字在网络中传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆