Add support for random available port number determination
This commit is contained in:
parent
f2329c1dfe
commit
f1dc5ad2ed
1 changed files with 14 additions and 0 deletions
14
essentials/services/ConnectionService.py
Normal file
14
essentials/services/ConnectionService.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionService:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_random_available_port_number():
|
||||||
|
|
||||||
|
socket_instance = socket.socket()
|
||||||
|
socket_instance.bind(('', 0))
|
||||||
|
port_number = socket_instance.getsockname()[1]
|
||||||
|
socket_instance.close()
|
||||||
|
|
||||||
|
return port_number
|
||||||
Loading…
Reference in a new issue