close() { if (this.closed) { return; } this.closed = true; if (this._interval) { clearInterval(this._interval); this._interval = null; } this.server.close(); this.emit('closed'); }
stop() { this.server.close(); process.exit(0); }
close() { if (this.closed) { return; } this.socket = undefined; this.closed = true; this.server.close(); this.emit('closed'); }
add(socket: net.Socket, data: Buffer) { if (this.state !== ST_STARTED) { return; } this.httpServer.emit('connection', socket); if (typeof (socket as any).ondata === 'function') { // compatible with stream2 (socket as any).ondata(data, 0, data.length); } else { // compatible with old stream socket.emit('data', data); } }
server.on('connection', function(stream) { var conn = mqttCon(stream); conn.on('connect', function() { console.log('connected'); }); conn.on('publish', function(packet) { // console.log(packet); conn.puback({ messageId: packet.messageId }) }); conn.on('pingreq', function() { conn.pingresp(); }); // conn is your MQTT connection! });
stop(force: boolean, cb: () => void) { this.switcher.close(); this.listeningServer.close(); process.nextTick(cb); }
constructor(server: net.Server, opts: HybridSwitcherOptions) { super(); this.server = server; this.wsprocessor = new WSProcessor(); this.tcpprocessor = new TCPProcessor(opts.closeMethod); this.id = 1; this.timeout = (opts.timeout || DEFAULT_TIMEOUT) * 1000; this.setNoDelay = opts.setNoDelay; if (!opts.ssl) { this.server.on('connection', this.newSocket.bind(this)); } else { this.server.on('secureConnection', this.newSocket.bind(this)); this.server.on('clientError', function (e, tlsSo) { logger.warn('an ssl error occured before handshake established: ', e); tlsSo.destroy(); }); } this.wsprocessor.on('connection', this.emit.bind(this, 'connection')); this.tcpprocessor.on('connection', this.emit.bind(this, 'connection')); this.state = ST_STARTED; }
}).listen(config.master.cwebport); console.log(' http server start at http://127.0.0.1:' + config.master.cwebport);
/** Terminate the server */ stop() { if (!this.running) { return; } this.running = false; this.connections.forEach(function (c) { c.destroy(); }); this.server.close(); this.server = null; this.emit('end'); }
/** Start the server listening on the given port */ start(robotMasterUrl: string , port?: number, hostname?: string) { if (this.running) { return; } this.running = true; this.robotMasterUrl = robotMasterUrl; let self = this; port = port || 8000; self.hostname = hostname || 'localhost'; self.port = port; self.connections = []; self.server = http.createServer(function (req, res) { self.route_(req, res); }); self.server.on('connection', function (c) { // We need to track incoming connections, beause Server.close() won't terminate active // connections by default. c.on('close', function () { let idx = self.connections.indexOf(c); if (idx !== -1) { self.connections.splice(idx, 1); } }); self.connections.push(c); }); self.server.listen(this.port, this.hostname); self.emit('start', self.hostname, self.port); return self; }
close() { this.server.close(); }
close() { if (this.closed) { return; } this.closed = true; if (this._interval) { clearInterval(this._interval); this._interval = null; } this.server.close(); this.emit('closed'); }
close() { if (this.closed) { return; } this.closed = true; if (this._interval) { clearInterval(this._interval); this._interval = null; } this.server.close(); this.emit('closed'); }
close() { if (this.closed) { return; } this.closed = true; if (this._interval) { clearInterval(this._interval); this._interval = null; } this.server.close(); this.emit('closed'); }
server.on('connection', function(stream) { var conn = mqttCon(stream); conn.on('connect', function() { console.log('connected'); }); conn.on('publish', function(packet) { // console.log(packet); conn.puback({ messageId: packet.messageId }) }); conn.on('pingreq', function() { conn.pingresp(); }); // conn is your MQTT connection! });