Hi,
I have a http server,when there is a GET request,I want to fetch some data
from my tcp backend server.
Now the question is,by using net.Socket,I can only get the response by
listening the 'data' event.
so in my code:
#get a tcp connection to my tcp backend server
net=require 'net'
socket=net.Socket()
socket.connect 8001
socket.on 'connect',()->
console.log "connected #{socket.remoteAddress} #{socket.remotePort}"
socket.on 'error',(exception)->
console.log "exception:#{exception}"
socket.on 'close',(had_error)->
msg='fully,closed'
if had_error
msg+=': some error caused close'
console.log msg
setTimeout ()->
socket.connect 8001
console.log 'closed,reconnecting'
,1000
#get funciton in my http app
app.get '/test',(req,res)->
socket.write 'this is the test page\n'
socket.once 'data',(data)->
console.log "recv:#{data}"
res.send "this is the test page recv: #{data}"
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
--
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