websocket协议及应用

websocket协议是一个应用层协议,地位和http协议是一样的。

websocket最主要的作用是实现

 

<!DOCTYPE html>
<html lang="en">

<script>
    // 向后端发送一个websocket连接请求
    let ws = new WebSocket('ws://127.0.0.1:8070/websocket');
    ws.onmessage = function (event) {
        console.info(`${event.type}:${event.data}`);
    }
</script>

</body>
</html>

后端代码见https://gitlab.com/koushr/websocket_server

在nginx需要配置:

    location /chat/v1/ws {
        proxy_pass http://lovelink_service;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

 

posted on 2020-09-04 09:57  koushr  阅读(191)  评论(0)    收藏  举报

导航