diff --git a/example-project/pom.xml b/example-project/pom.xml new file mode 100644 index 0000000..10fb7bc --- /dev/null +++ b/example-project/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + example-project + example-project + 1.0-SNAPSHOT + + + + my.mvn.repo + https://github.com/keesun/mvn-repo/raw/master + + + + + + com.nhncorp + mod-socket-io + 1.0.0 + + + + \ No newline at end of file diff --git a/example-project/src/main/java/whiteship/EchoServer.java b/example-project/src/main/java/whiteship/EchoServer.java new file mode 100644 index 0000000..d01141c --- /dev/null +++ b/example-project/src/main/java/whiteship/EchoServer.java @@ -0,0 +1,38 @@ +package whiteship; + +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.core.Handler; +import org.vertx.java.core.http.HttpServer; +import org.vertx.java.core.json.JsonObject; +import org.vertx.java.platform.Verticle; + +/** + * @author Keesun Baik + */ +public class EchoServer extends Verticle { + + @Override + public void start() { + int port = 9999; + HttpServer server = vertx.createHttpServer(); + SocketIOServer io = new DefaultSocketIOServer(vertx, server); + + io.sockets().onConnection(new Handler() { + @Override + public void handle(final SocketIOSocket socket) { + socket.emit("Hello"); + socket.on("/news", new Handler() { + @Override + public void handle(JsonObject data) { + System.out.println(data); + socket.emit(data); + } + }); + } + }); + + server.listen(port); + } +}