Skip to content

Commit

Permalink
Added example project
Browse files Browse the repository at this point in the history
  • Loading branch information
Keesun Baik committed Jul 12, 2013
1 parent bc5de45 commit b74a0ac
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
26 changes: 26 additions & 0 deletions example-project/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>example-project</groupId>
<artifactId>example-project</artifactId>
<version>1.0-SNAPSHOT</version>

<repositories>
<repository>
<id>my.mvn.repo</id>
<url>https://github.com/keesun/mvn-repo/raw/master</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.nhncorp</groupId>
<artifactId>mod-socket-io</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

</project>
38 changes: 38 additions & 0 deletions example-project/src/main/java/whiteship/EchoServer.java
Original file line number Diff line number Diff line change
@@ -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<SocketIOSocket>() {
@Override
public void handle(final SocketIOSocket socket) {
socket.emit("Hello");
socket.on("/news", new Handler<JsonObject>() {
@Override
public void handle(JsonObject data) {
System.out.println(data);
socket.emit(data);
}
});
}
});

server.listen(port);
}
}

0 comments on commit b74a0ac

Please sign in to comment.