简体   繁体   中英

java nio socketchannel: client to multiple servers

my project is actually pretty basic, but I just can't find the right information for it (ie: I can only find how to create a server that accepts multiple clients).

The idea is quite simple:
I want to create a client to will connect to multiple servers, and query stuff from them + await autonomous messages.
To give a rough idea, I want to create a simple program that will monitor multiple servers by creating a SSH connection to them (using Jsch), doing a login, sending 1 command every minute to retrieve all the alarms on the server. And the servers will also send alarms as soon as they appear.

my question is then: does anyone have any example on how to proceed ? any tutorial ? (google was not of much help, but maybe I did not try hard enough).

note: I am already able to do the same using a regular Socket in a Thread, but since I want to poll thousands of servers, I was told that opening an equal number of Threads+Sockets was a bad idea ...

I doubt that you will find an implementation of SSH that works over NIO.

I further doubt that there is any point. The protocol is heavyweight enough that conserving threads by using NIO just won't make any difference, or in fact will make it worse by starving the other channels of service while you're encrypting and decrypting for whatever channel your NIO thread is currently servicing. And given that you're really polling at 1 minute intervals there never was much of a reason to use NIO in the first place.

Use JSch or Ganymed SSH or one of the other SSH libraries, threads, and get on with your life.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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