Created
August 27, 2012 09:48
-
-
Save keesun/3487021 to your computer and use it in GitHub Desktop.
Socket.IO Module for Vert.x Sample Code
This file contains hidden or 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.nhncorp.test; | |
import com.nhncorp.mods.socket.io.SocketIOServer; | |
import com.nhncorp.mods.socket.io.SocketIOSocket; | |
import com.nhncorp.mods.socket.io.impl.DefaultSocketIOServer; | |
import org.vertx.java.busmods.BusModBase; | |
import org.vertx.java.core.Handler; | |
import org.vertx.java.core.http.HttpServer; | |
import org.vertx.java.core.impl.VertxInternal; | |
import org.vertx.java.core.json.JsonObject; | |
/** | |
* @author Keesun Baik | |
*/ | |
public class SocketIoServerTest extends BusModBase { | |
@Override | |
public void start() { | |
super.start(); | |
HttpServer server = vertx.createHttpServer(); | |
SocketIOServer io = new DefaultSocketIOServer(vertx, server); | |
io.sockets().onConnection(new Handler<SocketIOSocket>() { | |
@Override | |
public void handle(final SocketIOSocket socket) { | |
JsonObject data = new JsonObject(); | |
data.putString("hello", "world"); | |
socket.emit("news", data); | |
System.out.println("Somebody comes in."); | |
socket.on("timer", new Handler<JsonObject>() { | |
@Override | |
public void handle(JsonObject event) { | |
socket.emit("timer", event); | |
} | |
}); | |
socket.onDisconnect(new Handler<JsonObject>() { | |
@Override | |
public void handle(JsonObject event) { | |
System.out.println("somebody went out"); | |
} | |
}); | |
} | |
}); | |
server.listen(9090); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment