I have two machines. One machine is a client and the other is a server running JBoss. I have no trouble having the client make requests and the server respond to those requests. However, for a new project that I need to do I have to reverse the roles. I have to implement a push model, so the server will need to make requests from the client. Specifically I need the server to be able to ask the client for files in a directory, copy files from the server to the client, and run programs on the client. I'd like to do this without adding a ps开发者_如何学Pythonedo server on the client (a small daemon process).
Is there a good way to do this?
Thanks
EDIT: So it would appear that I have to set up a server on the client machine to do what I need because I need to have the server push to the client while the client is not running the Java process (but the machine is on). With that in mind, what's the lightest weight Java server?
Is there any reason why you don't want to add a server process to the client ?
A simple implementation (to my mind) would be to embed an HTTP server like Jetty (which has a relatively small footprint) within your client. The client can then tell JBoss when it comes up (and where to find the client's Jetty) and then JBoss can just use HttpClient (or similar) to talk to the client.
If (as your comment suggests) you want to push to the machine whilst your client isn't running, then why not just install an sshd
daemon and use scp
via JSch ? You can install Cygwin sshd on Windows.
I'd like to do this without adding a psedo server on the client (a small daemon process). Is there a good way to do this?
No, not really. The client has to listen for incoming connections on some port in order for the server to initiate the communication.
There are other "push"-techniques that emulate push, such as "long polling" etc. The Push technology Wikipedia article lists the following techniques for instance:
- HTTP server push
- Pushlet
- Long polling
- Flash XMLSocket relays
run programs on the client..... without adding a psedo server on the client
You cannot have the cake and eat it too. If you need to command another host to execute a program then the other host need to have some process that listens for the command. So the question boils down to finding the most lightweight or simplest solution.
The simplest solution would be to use shared folders for listing files and copying files and to use RMI for executing remote programs. More complex options involve developing a Distributed Agent using tools like JADE , using messaging middle-wares,say,JMS or using multi-casting tools like jGroups.
PS: Developing a custom SNMP agent and manager might also work
One way to simulate server push is Comet.
You can use JMS (Java Message Service) to push notifications from the server to its clients. JMS is a specialized protocol that allows you to efficiently push small messages between two or more applications. The scenario you describe is commonly implemented with JMS.
For example:
- A client subscribes to a JMS topic on the JBoss server
- The server sends a message to the JMS topic. The message payload could e.g. be command ID to list directory.
- The client receives the JMS message, performs the command and calls service on server to return the result.
If you have multiple client applications and need to push notifications to individual client instances, then one solution is to have the server assign a unique ID to each client, which will be used to filter the JMS messages.
精彩评论