当前位置:   article > 正文

ws协议绑定服务器域名,Websocket直接域名连接

python websocket 绑定域名

Websocket使用 ws 或 wss 的统一资源标志符,类似于 HTTP 或 HTTPS,其中 wss 表示在 TLS 之上的 Websocket ,相当于 HTTPS 了。

默认情况下,Websocket 的 ws 协议使用 80 端口;运行在TLS之上时,wss 协议默认使用 443 端口。其实说白了,wss 就是 ws 基于 SSL 的安全传输,与 HTTPS 一样样的道理

配置Nginx支持wss

# 我的配置在https的nginx下面

location /usign {

proxy_pass http://127.0.0.1:9990/;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header REMOTE-HOST $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 5000M;

}

代码中的使用

vue中配置

我这里用在了vue里面,工程使用的脚手架。websocket用在了app.vue里面,因为我的是全局的监听。从服务器上面回来的数据,可以通过vue的store来改变其他页面的数据

import { mapState, mapMutations } from 'vuex'

export default {

name: 'App',

data () {

return {

websock: null,

reconnectData: null,

lockReconnect: false,

timeout: 10000,

timeoutObj: null,

serverTimeoutObj: null

}

},

computed: {

...mapState([

'currentUser',

'identificationDevice',

'logshow'

])

},

created () {

document.title = ''

this.initWebSocket()

},

methods: {

...mapMutations([

'updatePromptBtn',

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/962283
推荐阅读
相关标签
  

闽ICP备14008679号