简体   繁体   English

如何在两台计算机之间传递大量数据

[英]How to pass a lot of data between two computers

What are possible options to transfer a lot of data from one computer to another not in the same LAN. 有哪些可能的选项将大量数据从一台计算机传输到不在同一LAN中的另一台计算机。 The amount of data is about 100Mb unzipped and 2Mb zipped? 压缩后的数据量约为100Mb,压缩后的数据量约为2Mb? Another requirement is that when I create a server for this (with C#) Java clients should be able to consume it. 另一个要求是,当我为此服务器(使用C#)创建服务器时,Java客户端应该能够使用它。

  • Does WCF support something like this? WCF是否支持这样的功能? But if Java clients won't be able to consume it I'm not interested. 但是,如果Java客户端无法使用它,我将不感兴趣。
  • What could be other strategies here? 这里还有什么其他策略?

I'd just use something common like HTTP or FTP, since there will be plenty of existing libraries to do it and you're pretty much guaranteed not to have compatibility problems. 我将仅使用HTTP或FTP之类的通用名称,因为将有很多现有的库可以执行此操作,并且可以保证您不会遇到兼容性问题。 2MB is not an unreasonably large amount of data for those protocols. 对于那些协议,2MB并不是大量的数据。

This is an interesting kind of question. 这是一个有趣的问题。 The question is fairly simple to answer. 这个问题很容易回答。 But the interesting thing is that this kind of questions are new, they didn't exists before. 但是有趣的是,这种问题是新的,以前不存在。 Let me explain, but first I will answer your question: 让我解释一下,但首先我将回答您的问题:

You should create a server and clients both using old fashion TCP streams. 您应该使用旧式TCP流创建服务器和客户端。 To not waist bandwidth you need to compress the stream somehow, here use one of the most common compression algorithms you can find (anyone said Zip?). 为了不增加带宽,您需要以某种方式压缩流,这里使用您可以找到的最常见的压缩算法之一(有人说Zip吗?)。 Now you have a language independent protocol. 现在,您有了独立于语言的协议。 Clients in any language will work, mission accomplished. 任何语言的客户都将工作,完成任务。 Also to keep it cross-platform, do not pick the best compression out there, pick the most common one (It will be good enough). 同样,为了保持跨平台,请不要选择最佳的压缩方式,而应选择最常用的压缩方式(这样就足够了)。

Now to why this kind of questions are interesting, they show something about OOP on the large scale. 现在,为什么这类问题很有趣,它们在很大程度上展示了有关OOP的一些知识。 People understanding and using huge frameworks and asking if this or that framework can perform this or that simple task for them. 人们理解并使用庞大的框架,并询问该框架是否可以为他们执行此或那个简单的任务。 Here we have lose our roots, we have lost the inner workings of things, it's hitting the nail not with a hammer but with a nuclear missile. 在这里,我们失去了根源,失去了事物的内部运作,它不是用锤子而是用核导弹击中了钉子。 It's overshooting the target, and it will produce huge applications, with huge footprint and often poor performance. 它超出了目标,将产生大量的应用程序,具有巨大的覆盖范围,并且性能通常很差。

I believe that this questions has increased in number since OOP was fully adopted. 我认为,自从完全采用OOP以来,这个问题的数量就增加了。 It's like new programmers only want to learn these new big frameworks and that the framework dim the view of the world. 就像新程序员只想学习这些新的大型框架,并且该框架使世界的视野变暗了。 There is absolutely nothing wrong with big frameworks, they are great, but I believe it's wrong to start out using them before one have mastered the basics. 大型框架绝对没有错,它们很棒,但是我认为在掌握基础知识之前就开始使用它们是错误的。 It's like learning to fly using a NASA space shuttle instead of a school version of a Cessna private airplane. 这就像使用NASA航天飞机而不是学校版本的塞斯纳私人飞机学习飞行一样。

In C# you can serialize your object as an XML and transmit, on the other end your can deserialize your XML back to an object. 在C#中,您可以将对象序列化为XML并进行传输,另一方面,可以将XML反序列化为对象。

In terms of files size, you can transmit as zipped or 7z..and on the client decompress it before parsing the xml. 在文件大小方面,您可以以压缩或7z ...格式传输,并在客户端上将其解压缩后再解析xml。

WCF supports SOAP and includes optional JSON serialization for XHTTP. WCF支持SOAP,并包括针对XHTTP的可选JSON序列化。 There are other mechanisms but they are MS orientated. 还有其他机制,但是它们是面向MS的。 You will easily be able to consume the service you create. 您将可以轻松使用创建的服务。 However you will have to consider how to encode the data as it will hit the wire in a non binary data friendly manner (XML/JSON). 但是,您将不得不考虑如何编码数据,因为它将以非二进制数据友好方式(XML / JSON)传递数据。

You may wish to instead create a simple http handler that can return the data directly as zip using appropriate mime headers etc. You should then be able to just hit that using your Java client. 您可能希望创建一个简单的http处理程序,该处理程序可以使用适当的mime标头等直接以zip格式返回数据。然后,您应该能够使用Java客户端访问该数据。

XMPP is another option. XMPP是另一种选择。 You need another server, but this could be an advantage: the client wouldn't need to know the servers IP address, server and clients would simply connect to the XMPP server to exchange message and files. 您需要另一个服务器,但这可能是一个优势:客户端不需要知道服务器的IP地址,服务器和客户端只需连接到XMPP服务器即可交换消息和文件。

Related links (for Java): 相关链接(对于Java):

You didn't mentioned what type of data do you want to send. 您没有提及要发送的数据类型。 So for keeping things simple I will suppose that you have data stream which can be converted to byte array. 为了简单起见,我假设您有可以转换为字节数组的数据流。 Content of the stream has to be in format which is understandable to both C# and Java! 流的内容必须采用C#和Java都可以理解的格式!

The best choice is to compress your data stream with GZip stream. 最好的选择是使用GZip流压缩数据流。 Gzip should be supported on Java. Java应该支持Gzip。 Than you can send that stream converted to byte array as response from your WCF service operation. 然后,您可以发送转换为字节数组的流作为WCF服务操作的响应。 You can use default text encoding which will convert byte array into Base64 encoded string. 您可以使用默认的文本编码,它将字节数组转换为Base64编码的字符串。 If your java client supports MTOM (it is standard which is supported by Java) than you can use MTOM encoding which uses smaller messages. 如果您的Java客户端支持MTOM(这是Java支持的标准),则可以使用使用较小消息的MTOM编码。

If you don't have a stream with well known content format you have some sort of custom data. 如果您没有具有众所周知的内容格式的流,则可以使用某种自定义数据。 For custom data you have to use interoperable transport format which is XML. 对于自定义数据,您必须使用XML的互操作传输格式。 Using XML will futher increase size of your data. 使用XML将进一步增加数据的大小。 In that case you should consider dividing your data transfer into several calls. 在这种情况下,您应该考虑将数据传输分为几个调用。 You can also try to host your WCF service in IIS 7.x and take advantage of its build in feature - compression of dynamic content. 您也可以尝试将WCF服务托管在IIS 7.x中,并利用其内置功能-动态内容压缩。 If your Java client calls the service with HTTP Accept-Encoding header set to compress, gzip it will automatically compress the response. 如果您的Java客户端使用HTTP Accept-Encoding标头设置为compress调用该服务,则使用gzip它将自动压缩响应。 Be aware that only .NET 4.0 WCF clients can work with such service. 请注意,只有.NET 4.0 WCF客户端可以使用此类服务​​。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM