node.js - Write After end error when post request happen -
'use strict'; var express = require('express'); var app = express(); var stomp = require('stomp-client'); var cors = require('cors'); var destination = '/topic/chat.'; var client = new stomp('127.0.0.1', 61613, 'admin', 'password'); var bodyparser = require('body-parser'); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: true })); app.use(cors()); app.post('/activemq', function(req, res) { var message = req.body.message; var con_id = req.body.conid; var send_destination = destination + "" + con_id var obj = new object(); obj.text = message; obj['corre-id'] = ""; var jsonstring = json.stringify(obj); client.connect(function(sessionid) { client.subscribe(send_destination, function(body, headers) { console.log(body); }); client.publish(send_destination, jsonstring); }); client.disconnect() res.json('success') }); app.listen(3000, function() { console.log('server listening on port 3000'); });
write after end error when post request happen.can please me
events.js:85 throw er; // unhandled 'error' event ^ error: write after end @ writeafterend (_stream_writable.js:167:12) @ socket.writable.write (_stream_writable.js:214:5) @ socket.write (net.js:634:40) @ stompframe.send (c:\users\jpsamaranayake\desktop\node\node_modu @ stompclient.onconnect (c:\users\jpsamaranayake\desktop\node\nod @ socket.emit (events.js:129:20) @ tcpconnectwrap.afterconnect [as oncomplete] (net.js:1001:10)
your trying send message client after disconnect.
from doc
when client disconnected, can no longer send or receive messages.
did try send response before closing connection?
res.json('success') client.disconnect()
Comments
Post a Comment