【发布时间】:2011-10-21 19:54:21
【问题描述】:
我可以在 C# 中同时将一个端口上的文件发送到多台计算机吗?就像我有代码要通过 System.Net.Sockets 在端口 1234 上发送,我想将文件发送到 5 台计算机。我可以同时做吗?
【问题讨论】:
-
这些电脑在一个局域网内吗?
标签: c# .net file sockets sendfile
我可以在 C# 中同时将一个端口上的文件发送到多台计算机吗?就像我有代码要通过 System.Net.Sockets 在端口 1234 上发送,我想将文件发送到 5 台计算机。我可以同时做吗?
【问题讨论】:
标签: c# .net file sockets sendfile
如果您的意思是使用一个端口作为目标端口,您可以这样做......
您需要使用Async 或Thread 使发送并行...您必须正确设置FileStream sharing 以便文件可以由不同线程并行打开.
见
http://msdn.microsoft.com/en-us/library/5h0z48dh.aspx
http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx
http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx
http://www.csharp-examples.net/create-new-thread/
http://www.developerfusion.com/article/3918/socket-programming-in-c-part-1/2/
编辑 - 根据评论:
没有区别...您可以使用ThreadPool 并为每个目标创建一个工作项...请参阅http://msdn.microsoft.com/de-de/library/system.threading.threadpool.aspx 和http://www.dotnetperls.com/threadpool
【讨论】: