简体   繁体   English

我们可以在客户端编程中使用选择器概念吗

[英]can we use selector concept in client side programming

I am developing an android application where it has to talk to multiple TCP based servers in run time. 我正在开发一个Android应用程序,它必须在运行时与多个基于TCP的服务器通信。 Now i am using java sockets to communicate and threads to handle multiple clients. 现在,我正在使用java套接字进行通信,并使用线程来处理多个客户端。 But there is a requirement in application that we need to talk to more numbers of servers in run time. 但是应用程序中有一个要求,我们需要在运行时与更多服务器进行对话。 So i am using the concept of Java NIO with selectors to handle multiple servers at a time. 因此,我使用带有选择器的Java NIO的概念来一次处理多个服务器。 But the problem now i am facing is that i am not able to communicate with any of the servers. 但是我现在面临的问题是我无法与任何服务器通信。 So please any one suggest can i use selector at client side. 因此,请任何建议我可以在客户端使用选择器。

You can use Selectors, but they add complexity to your coding. 您可以使用选择器,但它们会增加编码的复杂性。 I suggest you use a library like netty or mina to manage this for you. 我建议您使用netty或mina之类的库来为您管理。

An alternative is to use blocking NIO which is much simpler to use IMHO and have multiple threads. 一种替代方法是使用阻止NIO,这比使用IMHO更容易并且具有多个线程。 On a PC this can handle up to 1000 connections and on an Android device it might handle tens or so. 在PC上,它最多可以处理1000个连接,而在Android设备上,则可以处理数十个左右的连接。

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

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