如何在不使用xmpp或其他繁重协议的情况下将服务器警报推送到Java中的任务栏应用程序?

您是否建议实现此目的的方法?

我打算编写一个在配备Comet的服务器上使用URLConnection的应用程序,但我怀疑这是否可行,因为客户端需要调用JS且URLConnection不是浏览器。

什么是最好的推送方式而不是使用专有的客户端-服务器方式?

最佳答案

我在Mac上使用Growl接收来自我的应用的本地通知,但您也可以发送Growl远程通知。还有一个Windows versionJava library可用。这是示例Java代码(需要Java 6):

// give your application a name and icon (optionally)
Application serverApp = new Application("Server App");

// create reusable notification types, their names are used in the Growl settings
NotificationType start = new NotificationType("ServerStart");
NotificationType shutdown = new NotificationType("ServerShutdown");
NotificationType[] notificationTypes = new NotificationType[] {start, shutdown};

// connect to Growl on the given host
GrowlConnector growl = new GrowlConnector("localhost");

// now register the application in growl
growl.register(serverApp, notificationTypes);

// finally send the notification
growl.notify(new Notification(serverApp, start, "Server is starting", "Good luck"));

10-08 18:33