Package verticle

Source Code of verticle.SampleVerticle

package verticle;

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 SampleVerticle extends Verticle {

  @Override
  public void start() {
    int port = 9090;
    HttpServer server = vertx.createHttpServer();
    SocketIOServer io = new DefaultSocketIOServer(vertx, server);

    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      public void handle(final SocketIOSocket socket) {
        socket.on("timer", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            socket.emit("timer", event);
          }
        });
      }
    });

    System.out.println("server is running on http://localhost:" + port);
    server.listen(port);
  }
}
TOP

Related Classes of verticle.SampleVerticle

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.