Is it possible to send a request to an http server if you only have a reference to the server object?

40 views
Skip to first unread message

Greg Reimer

unread,
Jun 30, 2015, 12:02:49 PM6/30/15
to nod...@googlegroups.com
Basically, it would be nice to be able to create a server object that I could have in memory and connect to directly (for proxying purposes) *without* tying up a socket file or a TCP port.

I've been looking for a way to do this for a while actually, and it seems like it should be possible in principle, but have had no luck finding an example. Maybe it simply isn't possible?

Thanks,
Greg

Ryan Graham

unread,
Jun 30, 2015, 2:29:59 PM6/30/15
to nod...@googlegroups.com
If you only plan on using it from within the process, you could use an ephemeral port binding, which shouldn't "tie up" a useful TCP port.

~Ryan

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/58d97f08-1794-4a11-a5e5-56ed710579fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Reimer

unread,
Jun 30, 2015, 9:05:27 PM6/30/15
to nod...@googlegroups.com
That seems reasonable. I see nothing about working with "ephemeral ports" in the node/iojs docs, but suspect server.listen(0) (which listens on a "random" port) and then then connecting to whatever's in server.address() would be the way to do that. Assuming there isn't a better way I'll give that a try.

Thanks!

Ryan Graham

unread,
Jun 30, 2015, 10:37:36 PM6/30/15
to nod...@googlegroups.com
Yes, .listen(0) followed by .address().port is what I meant by " use an ephemeral port" :-)

~Ryan
Reply all
Reply to author
Forward
0 new messages