Error during WebSocket handshake: Unexpected response code: 502
在web頁面可以連接:
代碼:
import VueWebsocket from "vue-websocket" ; Vue.use(VueWebsocket, "wss://xxx.com/socket" , { reconnection: false }); |
服務(wù)端實(shí)現(xiàn):
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) } }) |
網(wǎng)友回復(fù):
解決了,在服務(wù)端用ws替換了socket.io,:)