@
verfino @
hoorace @
paloalto 试试我这个:
https://github.com/lvjian700/node-pusher基于socket.io,项目很简单,仅用来做数据推送:
web, java, ios 客户端都有。
Web端:
$(function() {
var url = 'http://localhost:3000/';
var room = '/column';
var pusher = new Pusher(url);
pusher.sub(room, function(data) {
console.log('subscribe /column room success.');
console.log(data);
});
pusher.on('news', function(data) {
console.log('receive data from xx room.');
console.log(data);
});
$('#btnSent').click(function() {
var text = $('#message').val();
pusher.pub(room, 'news', {sender: 'lvjian', msg: text});
$('#message').val('');
});
});
Java端:
public class Sample {
static String to = "/column";
static String event = "news";
public static void main(String[] args) throws MalformedURLException, JSONException {
Pusher pusher = new Pusher("http://127.0.0.1:3000/");
// This line is cached until the connection is establisched.
for(int i = 0; i < 10; i++) {
JSONObject json = new JSONObject();
json.put("msg", "haha");
pusher.pub(to, event, json.toString());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.exit(0);
}
}
iOS(尚未整理,
直接用的Socket.IO for Cocoas)
_socketIO = [[SocketIO alloc] initWithDelegate:self];
NSString *host = [RKObjectManager sharedManager].baseURL.host;
[_socketIO connectToHost:host onPort:3000];
[_socketIO sendEvent:@"sub" withData:@{@"topic" : @"/changji"}];
//...
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet {
//这里接收事件
}
@
nybux 求测试方案,我想对node-pusher服务做个性能测试。