Spaces:
Runtime error
Runtime error
Create socket.py
Browse files
socket.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import socket
|
2 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
3 |
+
s.bind(('', 0)) # bind to a random free port
|
4 |
+
port = s.getsockname()[1] # get the port number
|
5 |
+
s.close() # close the socket
|
6 |
+
print(port) # print the port number
|