This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.yongboy.chatdemo; | |
import org.apache.cordova.DroidGap; | |
import android.os.Bundle; | |
import com.strumsoft.websocket.phonegap.WebSocketFactory; | |
/** | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 在线画报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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yongboy = {}; | |
yongboy.eventbus = { | |
listeners : { | |
list : {}, | |
add : function(event, fn) { | |
this.list[event] = fn; | |
}, | |
remove : function(event) { | |
this.list[event] = null; |