On Feb 14, 4:54 am, cong <[email protected]> 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

Here's one solution I thought of off the top of my head:

Create a queue that contains entries (e.g. { res: res, data: 'foo' })
of the http response object and the data to send. Have a queue
processor function that takes an entry from the queue, sends the
specific data, and then writes to and ends the http response. If the
queue is not empty after the http response is ended, then continue
processing the queue until it's empty.

In your http request callback, simply push to the queue. If the
current queue length === 1, then start the queue processor function,
otherwise do nothing else.

-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to