收藏
回答

websocket连接问题

问题模块
API和组件

Error during WebSocket handshake: Unexpected response code: 502


在web页面可以连接:

代码:

import VueWebsocket from "vue-websocket";
Vue.use(VueWebsocket, "wss://xxx.com/socket", {
    reconnection: false
});


服务端实现:

var http = require('http').Server(express)
var io = require('socket.io')(http)
 
io.on('connection', function (socket) {
    console.log('a client connected')
    socket.emit('news', { hello: 'world' })
})
 
http.listen(config.io.port, function () {
    console.log('listening on *:' + config.io.port)
})


小程序代码:

wx.connectSocket({
    url: 'wss://xxx.com/socket',
    success: function (res) {
       console.log(res)
    }
})


最后一次编辑于  2017-04-29  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏