var socket;
function openSocket(loginName) {
    if(typeof(WebSocket) == "undefined") {
        console.log("您的浏览器不支持WebSocket");
    }else{
        console.log("您的浏览器支持WebSocket");
        var socketUrl="http://localhost:9090/business/app/websocket/"+loginName;
        // var socketUrl="http://127.0.0.1/business/app/websocket/"+loginName;
        socketUrl=socketUrl.replace("https","ws").replace("http","ws");
        console.log(socketUrl);
        if(socket!=null){
            socket.close();
            socket=null;
        }
        socket = new WebSocket(socketUrl);
        //打开事件
        socket.onopen = function() {
            console.log("websocket已打开");
            //socket.send("这是来自客户端的消息" + location.href + new Date());
        };
        //获得消息事件
        socket.onmessage = function(msg) {
            // var text ='{"content":"String content","id":"0d44d0027e424e898f60a456ca8b8a6a","latitude":"5318807.94","longitude":"13874773.35","title":"String title"}';
            var message = msg.data;
            if(message != "" && message != null){

                // var json =  $.parseJSON(msg.data);
                var json =  message;
                console.log(message.content);
                console.log(json);

                getVisualization();


            }
        };
        //关闭事件
        socket.onclose = function() {
            console.log("websocket已关闭");
        };
        //发生了错误事件
        socket.onerror = function() {
            console.log("websocket发生了错误");
        }
    }
}
openSocket("sun11")
