Expose us_socket_local_port
(#547)
Usage: ```ts const token: us_socket_t; const port = uWS.us_socket_local_port(token); ```
This commit is contained in:
parent
6d88f857d0
commit
9b3efbdfa3
2 changed files with 27 additions and 0 deletions
20
examples/AutomaticPortSelection.js
vendored
Normal file
20
examples/AutomaticPortSelection.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Same as HelloWorld, but with automatic port selection. */
|
||||
|
||||
const uWS = require('../dist/uws.js');
|
||||
let port = 0;
|
||||
|
||||
const app = uWS./*SSL*/App({
|
||||
key_file_name: 'misc/key.pem',
|
||||
cert_file_name: 'misc/cert.pem',
|
||||
passphrase: '1234'
|
||||
}).get('/*', (res, req) => {
|
||||
res.end('Hello World!');
|
||||
}).listen(port, (token) => {
|
||||
if (token) {
|
||||
// retrieve listening port
|
||||
port = uWS.us_socket_local_port(token);
|
||||
console.log('Listening to port ' + port);
|
||||
} else {
|
||||
console.log('Failed finding available port');
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue