来自Web服务器的低吼通知 [英] Growl Notifications from a Web Server

查看:85
本文介绍了来自Web服务器的低吼通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到Growl允许从网站发出Growl通知.有没有人尝试实现这一目标?

I notice that Growl allows for the possibility of Growl notifications from a website. Has anyone tried implementing this?

如果是,采取什么形式?您实现了多用户支持吗?而且,您能否提供任何代码示例(最好使用C#或Objective-C,但我并不那么在意)?

If so, what form did it take? Did you implement multi user support? And, can you provide any code examples (C# or Objective-C would preferable but I'm not that fussed)?

丰富

推荐答案

GNTP (各种语言的增长网络传输协议)绑定,可以在此处找到绑定列表-这些允许您从PHP脚本发送通知.

There are GNTP (Growl Network Transport Protocol) bindings for various languages, a list of bindings can be found here - these allow you to send notifications from, say, a PHP script.

我不会直接信任Growl的UDP系统,而是编写一个服务器来接收和存储通知(也许是一个小型的Web应用程序),以及一个本地脚本,该脚本通常会通过HTTP抓取任何新消息并将Growls接收.一点也不复杂,它将比UDP更可靠,并且可以在Growlinging机器断电或无法访问时将消息排队.应该花很长时间来实现

I wouldn't trust Growl's UDP system directly, but rather write a server that receives and stores notifications (maybe as a tiny web app), and a local script that routinely grabs any new messages via HTTP and Growls them. Not complicated at all, will be more reliable than UDP, and can queue up messages when your Growl'ing machine is powered-off or unreachable. Shouldn't take long to implement

基本上是伪PHP中的server.php(可以使用 Net_Growl ):

Basically, server.php in pseudo-PHP (which could use Net_Growl):

<?php
if($_GET['action'] == "store"){
    $title = $_POST['title'];
    $message = $_POST['message'];
    $password = sha1($_POST['password']);
    if($password == "..."){
        store_in_database(sanitise($title), sanitise($message);
    }
} else {
    print(json_encode(get_notifications_from_database()));
    mark_notifications_as_read();
}
?>

client.py在伪Python中(可以使用 gntp ):

client.py in pseudo-Python (which could use gntp):

while 1:
    time.sleep(60):
    data = urllib.urlopen("http://myserver.com/server.php?action=get&password=blah").read()
    for line in data:
        notif = json.decode(line)
        growl.alert(notif['title'], notif['message'])

这篇关于来自Web服务器的低吼通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆