鍍金池/ 問答/Java  HTML/ 前端使用VueStomp后端用sockjs-node,官方事例連接失敗

前端使用VueStomp后端用sockjs-node,官方事例連接失敗

<template>
  <div class="page">
    <button @click="connectSrv">Link</button>
    <button @click="disconnect">UnLink</button>
    <button @click="send">send</button>
    <input type="text" v-model="val">
  </div>
</template>

<script>
  export default {
    data() {
      return {
        invokeIdCnt: 0,
        val: ''
      }
    },
    methods: {
      getInvokeId() {
        let hex = (this.invokeIdCnt++).toString(16);
        var zero = '0000';
        var tmp = 4 - hex.length;
        return zero.substr(0, tmp) + hex;
      },
      onFailed(frame) {
        console.log('連接失敗: ' + JSON.stringify(frame));
      },
      responseCallback(frame) {
        console.log("接收信息:" + frame.body);
      },
      disconnect() {
        this.disconnetWM();
      },
      onConnected(frame) {
        console.log('連接成功: ' + frame);
        this.$stompClient.subscribe('/echo', this.responseCallback, this.onFailed);
      },
      connectSrv() {
        this.connetWM("http://localhost:3001/echo", {}, this.onConnected, this.onFailed);
      },
      send() {
        let destination = '/echo'
        let invokeId = this.getInvokeId();
        let body = this.val
        this.sendWM(destination, body, invokeId, this.responseCallback, 3000);
      },
    },
    stompClient: {
      monitorIntervalTime: 100,
      stompReconnect: false,
      timeout(orgCmd) {}
    }
  };

</script>
var http = require('http');
var sockjs = require('sockjs');

var echo = sockjs.createServer({sockjs_url: './sockjs.min.js'});

echo.on('connection', function (conn) {
  conn.on('data', function (message) {
    conn.write(message);
    // console.log(message)
  });
  conn.on('close', function () {});
});

var server = http.createServer();
echo.installHandlers(server, { prefix: '/echo' });
server.listen('3001');

提示為

Opening Web Socket...
Web Socket Opened...
>>> CONNECT
accept-version:1.2,1.1,1.0
heart-beat:10000,10000

>>> length 60

<<< CONNECT
accept-version:1.2,1.1,1.0
heart-beat:10000,10000

Unhandled frame: CONNECT
heart-beat:10000,10000
accept-version:1.2,1.1,1.0

沒有提示連接成功或者失敗,應該是一直連接用,使用的官方事例
搞了一下午實在想不出來,求教下大神

回答
編輯回答
苦妄

請問解決了 最近也要用到stomp, 但是發(fā)現(xiàn)作者都不維護項目了

2017年11月29日 14:59