ozgurix commited on
Commit
e231bdc
1 Parent(s): c5dc572

Create socket.py

Browse files
Files changed (1) hide show
  1. socket.py +6 -0
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