On Feb 14, 4:54 am, cong <king6c...@gmail.com> wrote: > as we know,multiple get requests can arrive at the same time, which means > there will be mutiple listeners on 'data' event, when my backend tcp server > give a response, multiple get funciton recv the data at the same time, but I > only want the response of their own. > > are there some workaround,all is it true that we can't use one tcp connection > for serving multiple users? > > any help is appreciated
If you really want to do it in parallel instead, you'll probably need to have your tcp backend tag responses using some id that is unique to each connection so that each http request knows if specific incoming data is meant for it or another http request. Additionally, you might consider writing a class or function that wraps the tcp stream and emits events containing whole incoming messages, to make things a little easier. This would allow you to do something like: // inside http request handler streamWrapper.write('foo'); streamWrapper.once(someUniqueId, .....); // or use .on() if you expect more than one message, but remember to remove the event handler later on so as to prevent leaking // inside streamWrapper somewhere after forming a complete incoming message streamWrapper.emit(uniqueIdFromData, ....); -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en