Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2013-04-29 17:55:09 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2013-05-07 11:56:17 (GMT)
commita6b7c2768f30d71d4ca1c2cafd2da8e6e03fb812 (patch)
tree263822ae1b95c988ba69fe8d39df083e539263c4 /activity.py
parent56234e7278471c30b424e3b5b8e395e22d5756d6 (diff)
Use a free port instead of using 2500 fixed
This allow have more than one instance running at the same time and improve reliability, if for any reason the port is in use. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/activity.py b/activity.py
index 0416b35..dd19b64 100644
--- a/activity.py
+++ b/activity.py
@@ -26,6 +26,7 @@ import telepathy
import dbus
import os.path
import json
+import socket
from sugar3.activity import activity
from sugar3.activity.widgets import ActivityToolbarButton
@@ -64,8 +65,16 @@ class JournalShare(activity.Activity):
self._jm = JournalManager(self._activity_root)
self.server_proc = None
- self.port = 2500
+
if not self.shared_activity:
+ # Get a free socket
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
+ sock.bind(('', 0))
+ sock.listen(socket.SOMAXCONN)
+ _ipaddr, self.port = sock.getsockname()
+ sock.shutdown(socket.SHUT_RDWR)
+ logging.error('Using port %d', self.port)
+
#TODO: check available port
server.run_server(self._activity_path, self._activity_root,
self._jm, self.port)