package org.dorydory.websocket;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Handler;
import io.vertx.core.http.ServerWebSocket;
import org.dorydory.websocket.util.Runner;
import io.vertx.core.logging.Logger;

public class Server extends AbstractVerticle {

    public static void main(String[] args) {
        Runner.runExample(Server.class);
    }

    @Override
    public void start() throws Exception {

        vertx.createHttpServer().websocketHandler(new Handler<ServerWebSocket>() {
            @Override
            public void handle(final ServerWebSocket ws) {
                ws.writeFinalTextFrame("Connected Succesfully!");

                ws.handler(new Handler<Buffer>() {
                    @Override
                    public void handle(final Buffer data) {
                        ws.writeFinalTextFrame(data.toString());
                    }
                });

            }
        }).listen(8080);
    }
}

@@ -258,55 +258,228 @@
 er;%0A
-%0Apublic class Server extends AbstractVerticle %7B
+import io.vertx.core.json.JsonObject;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class Server extends AbstractVerticle %7B%0A    HashMap%3CString, ServerWebSocket%3E clients = new HashMap%3CString,ServerWebSocket%3E();
 %0A%0A  
@@ -835,43 +835,655 @@
 me(%22
-Connected Succesfully!%22);%0A%0A        
+url: %22+ws.path());%0A                switch(ws.path()) %7B%0A                    case %22/register%22:%0A                        register(ws);%0A                        break;%0A                    case %22/chat%22:%0A                        clients.put(ws.binaryHandlerID(),ws);%0A                        chat(ws);%0A                        break;%0A                    default:%0A                        ws.writeFinalTextFrame(%22404 NOT FOUND!%22);%0A                        System.out.println(%22Unexpected connection detected!%22);%0A                        return;%0A                %7D%0A            %7D%0A        %7D).listen(8080);%0A    %7D%0A%0A    private void register(final ServerWebSocket ws) %7B%0A
     
@@ -1529,32 +1529,24 @@
             
-     
-   
 @Override%0A  
@@ -1539,32 +1539,24 @@
   @Override%0A
-        
             
@@ -1591,28 +1591,57 @@
 fer data) %7B%0A
+/*%0A
     
+            while(true) %7B%0A
             
@@ -1685,24 +1685,25 @@
 oString());%0A
+%0A
             
@@ -1692,32 +1692,44 @@
 ());%0A%0A          
+      %7D%0A%0A*/%0A
           %7D%0A    
@@ -1714,32 +1714,34 @@
 %7D%0A%0A*/%0A          
+  
 %7D%0A              
@@ -1738,57 +1738,1043 @@
     
-        %7D);%0A%0A            %7D%0A        %7D).listen(8080
+%7D);%0A%0A    %7D%0A%0A    public void chat(final ServerWebSocket ws) %7B%0A%0A        ws.closeHandler(new Handler%3CVoid%3E() %7B%0A            @Override%0A            public void handle(Void arg0) %7B%0A                clients.remove(ws.binaryHandlerID());%0A            %7D%0A        %7D);%0A%0A        ws.handler(new Handler%3CBuffer%3E() %7B%0A            @Override%0A            public void handle(final Buffer data) %7B%0A                String inputString = data.toString();%0A                JsonObject jsonObject = new JsonObject(inputString);%0A                String msg = jsonObject.getString(%22msg%22);%0A/*%0A                Object object = JSONValue.parse(inputString);%0A                JSONObject Jobj = (JSONObject) object;%0A%0A                String msg = Jobj.get(%22msg%22).toString();%0A */%0A                System.out.println(%22%22 + clients.size());%0A                for (Map.Entry%3CString, ServerWebSocket%3E entry : clients.entrySet()) %7B%0A                    ServerWebSocket client = entry.getValue();%0A                    client.writeFinalTextFrame(msg);%0A                %7D%0A            %7D%0A        %7D
 );%0A 
@@ -2778,10 +2778,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

add chatting