• 实时通讯 的记录


    var userID="88";
        var websocket=null;
        $(function() {
    
            //创建WebSocket
            connectWebSocket();
        })
    
        //强制关闭浏览器  调用websocket.close(),进行正常关闭
        window.onunload = function() {
    
            //关闭连接
            closeWebSocket();
        }
    
        //建立WebSocket连接
        function connectWebSocket(){
    
            console.log("开始...");
    
            //建立webSocket连接
            websocket = new WebSocket("ws://10.131.103.153:8080/bbs/bbsChatHandler/ID="+userID);
    
            //打开webSokcet连接时,回调该函数
            websocket.onopen = function () {
                console.log("onpen");
            }
    
            //关闭webSocket连接时,回调该函数
            websocket.onclose = function () {
                //关闭连接
                console.log("onclose");
            }
    
            //接收信息
            websocket.onmessage = function (msg) {
                console.log(msg.data);
            }
        }
    
        //发送消息
        function send(){
            var postValue={};
            postValue.id=userID;
            postValue.message=$("#text").val();
            websocket.send(JSON.stringify(postValue));
        }
        //关闭连接
        function closeWebSocket(){
            if(websocket != null) {
                websocket.close();
            }
        }
  • 相关阅读:
    O(n)回文子串(Manacher)算法
    LightOJ 1282
    LightOJ
    LightOJ
    POJ-2563
    POJ-2398
    POJ-2318
    ZOJ-3318
    [svc]ftp协议数据连接的2种模式
    [py]python中的特殊类class type和类的两面性图解
  • 原文地址:https://www.cnblogs.com/bozhiyao/p/9224265.html
Copyright © 2020-2023  润新知