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) } }) |