metarhia / jstp

Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
https://metarhia.github.io/jstp
Other
142 stars 10 forks source link

Getting the port a server is bound to #184

Closed nechaido closed 7 years ago

nechaido commented 7 years ago

We need an API to get a random free port. At the moment I have two ways to write test:

Both are not ok. It would be great to be able to get a random free port. Although, this feature may be prone to race condition.

tshemsedinov commented 7 years ago

Why do we need random ports? And for what reason? (maybe you propose it for tests) Good ways to do that:

@metarhia/jstp-core

lundibundi commented 7 years ago

@tshemsedinov Yes it's to be used in tests, at least for now (see https://github.com/metarhia/jstp/pull/183).

And this may indeed be prone to race conditions but I do not think we'll be able to see it in this project as it requires some real lot amount of simultaneous network tests to be run. But to avoid them completely this should probably be some sort of separate service which will keep track of pending requests.

aqrln commented 7 years ago

@tshemsedinov mainly for tests, yeah, but there may be different use cases.

FWIW, we do support random ports; this issue is a bit confusing. We need an API to get a port a server is bound to, and it has nothing to do with random ports per se.

@lundibundi bind(0) is not prone to race conditions, using hardcoded ports is ;)

lundibundi commented 7 years ago

@aqrln I meant in case of implementing something different than using bind(0) =).

tshemsedinov commented 7 years ago

@aqrln ok, it's clear after renaming