使用 PHP 和 Javascript 的 Google Talk Web 客户端
我对如何建立从网络浏览器到 Google Chat 的连接有疑问。 因为您无法使用 JS 直接连接到 Google 聊天服务器,所以我从服务器连接到 Google 聊天服务器。我使用 xmphp (http://code.google.com/p/xmpphp/) 连接谷歌聊天服务器。喜欢:
include("xmpp.php");
$conn = new XMPP('talk.google.com', 5222, 'user', 'password', 'xmpphp', 'gmail.com', $printlog=True, $loglevel=LOGGING_INFO);
$conn->connect();
while(!$conn->disconnected) {
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
foreach($payloads as $event) {
$pl = $event[1];
switch($event[0]) {
case 'message':
print "---------------------------------------------------------------------------------\n";
print "Message from: {$pl['from']}\n";
if($pl['subject']) print "Subject: {$pl['subject']}\n";
print $pl['body'] . "\n";
print "---------------------------------------------------------------------------------\n";
$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
if($pl['body'] == 'quit') $conn->disconnect();
if($pl['body'] == 'break') $conn->send("</end>");
break;
case 'presence':
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
break;
case 'session_start':
$conn->presence($status="Cheese!");
break;
}
}
}
这很好用。
但问题是,我如何连接到自己的服务器以将消息推送到网络浏览器上?
I have a question about establish a connection from my webbrowser to Google Chat.
Because you can not connect directly to the Google chat server with JS i connect from a server to the Google Chat server. I use xmphp (http://code.google.com/p/xmpphp/) to connect with the google chat server. Like:
include("xmpp.php");
$conn = new XMPP('talk.google.com', 5222, 'user', 'password', 'xmpphp', 'gmail.com', $printlog=True, $loglevel=LOGGING_INFO);
$conn->connect();
while(!$conn->disconnected) {
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
foreach($payloads as $event) {
$pl = $event[1];
switch($event[0]) {
case 'message':
print "---------------------------------------------------------------------------------\n";
print "Message from: {$pl['from']}\n";
if($pl['subject']) print "Subject: {$pl['subject']}\n";
print $pl['body'] . "\n";
print "---------------------------------------------------------------------------------\n";
$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
if($pl['body'] == 'quit') $conn->disconnect();
if($pl['body'] == 'break') $conn->send("</end>");
break;
case 'presence':
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
break;
case 'session_start':
$conn->presence($status="Cheese!");
break;
}
}
}
This works well.
But know is the question, how can i connect to my own server to push the message on the webbrowser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么,您必须在此页面上编写一个 php 脚本或函数,以返回要显示到 Web 浏览器的 HTML。
我建议使用 AJAX 来调用此脚本,并使用返回的内容填充 .innerHtml。
Well, you would have to write a php script or function on this page that returns the HTML to be displayed to the web browser.
I would suggest using AJAX to call this script, and populate a .innerHtml with the contents returned.