witten
/
luminotes
Archived
1
0
Fork 0

Made Luminotes Desktop try to default to a particular port number.

This commit is contained in:
Dan Helfman 2009-02-13 14:32:26 -08:00
parent 3da4f7e739
commit 6e693eaef3
2 changed files with 18 additions and 5 deletions

3
NEWS
View File

@ -1,4 +1,7 @@
1.6.6: ?
* Luminotes Desktop now attempts to always run on a particular port number,
which means that as long as it's running you can reach it from a constant
URL.
* Luminotes now recognizes "mailto:" links as external links, so you can
include links to email addresses within your notes.

View File

@ -9,11 +9,21 @@ username_postfix = os.environ.get( "USER" )
username_postfix = username_postfix and "_%s" % username_postfix or ""
# find an available TCP socket to listen on
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
sock.bind( ( "", 0 ) )
socket_port = sock.getsockname()[ 1 ]
sock.close()
def find_available_port( port_number = 0 ):
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
sock.bind( ( "", port_number ) )
socket_port = sock.getsockname()[ 1 ]
sock.close()
return socket_port
# find an available TCP socket to listen on. try the default port first, and if that's not
# available, then just grab any available port that the OS gives us
DEFAULT_PORT = 6520
try:
socket_port = find_available_port( DEFAULT_PORT )
except socket.error:
socket_port = find_available_port()