简体   繁体   English

使用套接字在JAVA中同时将客户端连接到多个服务器

[英]Connecting a Client to Multiple Servers Simultaneously in JAVA using Sockets

I want to implement a multi-threaded client socket in JAVA which will connect with multiple servers.. For eg.. The client will accept an array of numbers and split that array into two.. The two arrays will be sent to two servers and the result from the servers will be combined by the client to get the Final sorted array.. 我想在JAVA中实现一个多线程客户端套接字,它将与多个服务器连接。例如..客户端将接受一个数字数组并将该数组拆分为两个..这两个数组将被发送到两个服务器并且来自服务器的结果将由客户端组合以获得最终排序的数组。

Any help guys??? 任何帮助人???

Let's split the "client" meaning in 2: 让我们将“客户端”分为2:

  1. client application, the app which you're creating which will communicate with one or more servers 客户端应用程序,您正在创建的应用程序,它将与一个或多个服务器通信
  2. client-socket, a client side of a communication channel, which can be connected to maximum one server at any time 客户端套接字,通信信道的客户端,可以随时连接到最多一个服务器

As a side note, only server-sockets can handle multiple clients "at the same time" 作为旁注,只有服务器套接字可以“同时”处理多个客户端

Now, you can not have a client-socket connect to multiple servers, but you can have a client application connecting to multiple servers by having an instance of client-socket connect to each server. 现在,您不能将客户端套接字连接到多个服务器,但是您可以通过将客户端套接字实例连接到每个服务器来使客户端应用程序连接到多个服务器。

So what your client application needs to do, is manage a list of client-sockets that connect to your servers, and upon receiving all the replies, aggregate the answer. 因此,您的客户端应用程序需要做的是管理连接到您的服务器的客户端套接字列表,并在收到所有回复后汇总答案。

Apache hadoop是你在这种情况下必须使用的。

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

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