Hello遇到高速公路文档我无法打开连接任何人都可以帮助我。我创建了一个接受“ws”的服务器,但是我无法在connection.onopen中激活任何事件!!
enter code here
var WebSocketServer = require("ws").Server
var http = require("http")
var express = require("express")
var app = express()
var port = process.env.PORT || 8083
var fs = require('fs')
var socketio = require('socket.io')(http)
var request = require('request')
var parseString = require('xml2js').parseString
var autobahn = require('autobahn')
//require('node-monkey').start();
require('./router/route')(app);
app.set('views',__dirname + '/views');
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
var server = http.createServer(app)
server.listen(port)
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:8083/ws',
realm: 'realm1'}
);
connection.onopen = function (session) {
// 1) subscribe to a topic
function onevent(args) {
console.log("Event:", args[0]);
}
session.subscribe('com.myapp.hello', onevent);
// 2) publish an event
session.publish('com.myapp.hello', ['Hello, world!']);
};
connection.open();