Package com.nhncorp.mods.socket.io.impl

Examples of com.nhncorp.mods.socket.io.impl.DefaultSocketIOServer


  @Override
  public void start() {
    int port = 9191;
    HttpServer server = vertx.createHttpServer();
    final SocketIOServer io = new DefaultSocketIOServer(vertx, server);
    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      public void handle(final SocketIOSocket socket) {
        socket.on("subscribe", new Handler<JsonObject>() {
          public void handle(JsonObject data) {
            String room = data.getString("room");
            socket.join(room);
            socket.emit("join:" + room);

            print(io.sockets().manager().rooms());
            print(io.sockets().clients(room));
            print(io.sockets().manager().roomClients(socket.getId()));
          }


        });
        socket.on("emit", new Handler<JsonObject>() {
          public void handle(JsonObject data) {
            String room = data.getString("room");
            io.sockets().in(room).emit("emit", data);
          }
        });
        socket.on("unsubscribe", new Handler<JsonObject>() {
          public void handle(JsonObject data) {
            String room = data.getString("room");
            socket.leave(room);
            socket.emit("leave:" + room);

            print(io.sockets().manager().rooms());
            print(io.sockets().clients(room));
            print(io.sockets().manager().roomClients(socket.getId()));
          }
        });
      }
    });
    server.listen(port);
View Full Code Here


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

    final Namespace chat = io.of("/chat");
    chat.onConnection(new Handler<SocketIOSocket>() {
      public void handle(SocketIOSocket socket) {
        socket.on("namespace emit", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            chat.emit("msg", new JsonObject().putString("everyone", "in").putString("/chat", "will get"));
          }
        });
      }
    });

    final Namespace news = io.of("/news");
    news.onConnection(new Handler<SocketIOSocket>() {
      public void handle(SocketIOSocket socket) {
        socket.emit("item", new JsonObject().putString("news", "item"));
      }
    });
View Full Code Here

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

    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      public void handle(final SocketIOSocket socket) {
        socket.on("send", new Handler<JsonObject>() {
          public void handle(JsonObject message) {
            socket.broadcast().emit("msg", message);
          }
View Full Code Here

    @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
View Full Code Here

  @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);
          }
View Full Code Here

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

    io.configure(new Configurer() {
      public void configure(JsonObject config) {
        config.putString("transports", "websocket,flashsocket,xhr-polling,jsonp-polling,htmlfile");
//        config.putString("transports", "xhr-polling,jsonp-polling,htmlfile");
      }
    });

    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      public void handle(final SocketIOSocket socket) {
        io.sockets().emit("this", new JsonObject().putString("will", "be received by everyone"));

        socket.on("private message", new Handler<JsonObject>() {
          public void handle(JsonObject msg) {
            System.out.println("I received " + msg);
          }
        });

        socket.on("msg", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            socket.emit("msg", event);
          }
        });

        socket.on("event", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            socket.emit("event");
          }
        });

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

        socket.on("message", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            String message = event.getString("message");
            System.out.println(message);
            socket.send(message);
          }
        });

        socket.on("volatile", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            socket.volatilize().emit("volatile", new JsonObject().putString("msg", "hello"));
          }
        });

        socket.on("broadcast", new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            socket.broadcast().emit("broadcast");
          }
        });

        socket.onDisconnect(new Handler<JsonObject>() {
          public void handle(JsonObject event) {
            System.out.println("disconnect");
            io.sockets().emit("user disconnected");
          }
        });
      }
    });
View Full Code Here

  public static void main(String[] args) throws InterruptedException {
    int port = 9090;
    final Vertx vertx = new DefaultVertx();
    HttpServer httpServer = vertx.createHttpServer();

    SocketIOServer io = new DefaultSocketIOServer(vertx, httpServer);
    io.configure(new Configurer() {
      public void configure(JsonObject config) {
        config.putString("transports", "websocket,flashsocket,xhr-polling,jsonp-polling,htmlfile");
      }
    });

    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      public void handle(final SocketIOSocket socket) {
        System.out.println(socket.getId() + " is connected.");

        socket.on("timer", new Handler<JsonObject>() {
          public void handle(JsonObject data) {
View Full Code Here

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

    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      @Override
      public void handle(SocketIOSocket socket) {
        socket.on("newchannel", new Handler<JsonObject>() {
          @Override
          public void handle(JsonObject event) {
            System.out.println(event);
            newChannel(event.getString("channel"));
          }


        });
      }

      private void newChannel(String channel) {
        final Namespace namespace = io.of("/" + channel);
        namespace.onConnection(new Handler<SocketIOSocket>() {
          @Override
          public void handle(SocketIOSocket socket) {
            socket.on("message", new Handler<JsonObject>() {
              @Override
View Full Code Here

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

    io.sockets().onConnection(new Handler<SocketIOSocket>() {
      public void handle(final SocketIOSocket socket) {
        socket.on("set nickname", new Handler<JsonObject>() {
          public void handle(JsonObject name) {
            System.out.println("name: " + name);
            socket.set("nickname", name, new Handler<Void>() {
View Full Code Here

TOP

Related Classes of com.nhncorp.mods.socket.io.impl.DefaultSocketIOServer

Copyright © 2018 www.massapicom. 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.