Skip to content

Instantly share code, notes, and snippets.

@yongboy
yongboy / App.java
Created May 10, 2012 03:20
App.java
package com.yongboy.chatdemo;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import com.strumsoft.websocket.phonegap.WebSocketFactory;
/**
*
@yongboy
yongboy / websocket.js
Created May 10, 2012 03:29
websocket.js
(function() {
// window object
var global = window;
// WebSocket Object. All listener methods are cleaned up!
var WebSocket = global.WebSocket = function(url) {
// get a new websocket object from factory (check com.strumsoft.websocket.WebSocketFactory.java)
this.socket = WebSocketFactory.getInstance(url);
// store in registry
if(this.socket) {
@yongboy
yongboy / socket.io-client-websocket-part.js
Created May 10, 2012 03:36
socket.io client websocket 片段
(function (exports, io, global) {
exports.websocket = WS;
function WS (socket) {
io.Transport.apply(this, arguments);
};
io.util.inherit(WS, io.Transport);
WS.prototype.name = 'websocket';
@yongboy
yongboy / QueueFactory.java
Created May 21, 2012 07:37
QueueFactory.java
public final class QueueFactory {
private static final boolean useUnsafe = DetectionUtil.hasUnsafe();
private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(QueueFactory.class);
private QueueFactory() {
// only use static methods!
}
@yongboy
yongboy / QueueFactory.java
Created May 21, 2012 07:39
QueueFactory.java
public final class QueueFactory {
private static final boolean useUnsafe = DetectionUtil.hasUnsafe();
private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(QueueFactory.class);
private QueueFactory() {
// only use static methods!
}
@yongboy
yongboy / QueueFactory-modify.java
Created May 21, 2012 07:39
QueueFactory.java
public final class QueueFactory {
private static final boolean useUnsafe = DetectionUtil.hasUnsafe();
private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(QueueFactory.class);
private QueueFactory() {
// only use static methods!
}
@yongboy
yongboy / WhiteboardServer.java
Created May 23, 2012 01:48
在线画报socket.io服务器端示范
/**
* 在线画报socket.io服务器端示范
*
* @author yongboy
* @time 2012-3-27
* @version 1.0
*/
public class WhiteboardServer {
public static void main(String[] args) {
MainServer chatServer = new MainServer(new WhiteboardHandler(), 80);
@yongboy
yongboy / gist:2908999
Created June 11, 2012 07:59
静态加载示范代码
public static void main(String[] args) {
int port = 9000;
String envPort = System.getenv("VCAP_APP_PORT");
if (envPort != null && envPort.trim().length() > 0) {
port = Integer.parseInt(envPort.trim());
}
MainServer mainServer = new MainServer(port);
mainServer.addNamespace("API KEY 1", new LoadUserHandler("API KEY 1"));
@yongboy
yongboy / gist:2909027
Created June 11, 2012 08:11
前端示范代码
var socket = yourbase.load("08235-sdxd-d23523s-d23d");
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
......
var socket2 = yourbase.load("636346-dsaf-dedss-vds");
socket2.on('chat', function (data) {
@yongboy
yongboy / yongboy.eventbus.js
Created August 24, 2012 14:55
yongboy.eventbus.js
yongboy = {};
yongboy.eventbus = {
listeners : {
list : {},
add : function(event, fn) {
this.list[event] = fn;
},
remove : function(event) {
this.list[event] = null;