gpt4 book ai didi

java - 将警报推送到 Java 中的通知托盘应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:41:14 25 4
gpt4 key购买 nike

如何在不使用 xmpp 或其他重型协议(protocol)的情况下将服务器警报推送到 java 中的托盘应用程序?

您是否推荐一种方法来实现这一点?

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

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

最佳答案

我使用 Growl在我的 Mac 上接收来 self 的应用程序的本地通知,但您也可以发送 Growl 远程通知。还有一个 Windows version , 以及 Java 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"));

关于java - 将警报推送到 Java 中的通知托盘应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2925426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com