faye server for nodejs
在终端里输入
git clone https://github.com/i5ting/fayeserver.git
npm install
npm start
默认端口是4567
,如果需要,请修改index.js
文件。
npm run publish
在网页里
<script type="text/javascript"
src="http://at35.com:4567/faye/client.js">
</script>
<script type="text/javascript">
var client = new Faye.Client('http://at35.com:4567/faye', {
timeout : 120,
retry : 5
});
Logger = {
incoming: function(message, callback) {
console.log('incoming', message);
callback(message);
},
outgoing: function(message, callback) {
console.log('outgoing', message);
callback(message);
}
};
client.addExtension(Logger);
client.on('transport:down', function() {
// the client is offline
});
client.on('transport:up', function() {
// the client is online
});
var subscription = client.subscribe('/foo', function(message) {
// handle message
console.log(message);
});
setTimeout(function(){
var publication = client.publish('/foo', {text: 'Hi there, foo test'});
publication.then(function() {
alert('Message received by server!');
}, function(error) {
alert('There was a problem: ' + error.message);
});
},2000);
</script>
说明
/foo
是需要订阅的主题如果访问不了 http://at35.com:4567/faye/client.js
,请邮件给我,[email protected]
发布主题的http api 说明
通过curl命令测试本地POST
curl -d "key=foo&value=sss" http://127.0.0.1:4567/pub
测试线上环境
curl -d "key=foo&value=sss" http://at35.com:4567/pub
使用node发送post请求(java可以使用httpclient)
var request = require('request');
request.post({
url:'http://at35.com:4567/pub',
form: {
key:'foo',
value:'' + str
}
}, function(err,httpResponse,body){
/* ... */
if(err)
console.log(err);
})
检测步骤
sss
todo