Skip to content

Commit 8c73e3d

Browse files
authored
Merge pull request #41 from mdavidsaver/portno
Allow selection of server ports
2 parents 9705e52 + bb2b174 commit 8c73e3d

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

server/cf.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
# for local testing w/ firewall
1010
#addrlist = 127.255.255.255:5049
1111

12+
# Listen for TCP connections on this interface and port.
13+
# Port also used as source for UDP broadcasts.
14+
# Default uses wildcard address and a random port.
15+
#bind = 0.0.0.0:0
16+
1217
# Processing chain
1318
procs = cf
1419

server/demo.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# for local testing w/ firewall
1313
#addrlist = 127.255.255.255:5049
1414

15+
# Listen for TCP connections on this interface and port.
16+
# Port also used as source for UDP broadcasts
17+
# Default uses wildcard address and a random port.
18+
#bind = 0.0.0.0:0
19+
1520
# Processing chain
1621
# sequence of plugin names seperated by ','
1722
#

server/recceiver/application.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from twisted import plugin
99
from twisted.python import usage, log
1010
from twisted.internet import reactor, defer
11+
from twisted.internet.error import CannotListenError
1112
from twisted.application import service
1213

1314
from .recast import CastFactory
@@ -33,9 +34,11 @@ def __init__(self, config):
3334
self.tcptimeout = float(config.get('tcptimeout', '15.0'))
3435
self.commitperiod = float(config.get('commitInterval', '5.0'))
3536
self.maxActive = int(config.get('maxActive', '20'))
36-
self.bind = config.get('bind', '')
37+
self.bind, _sep, portn = config.get('bind', '').strip().partition(':')
3738
self.addrlist = []
3839

40+
self.port = int(portn or '0')
41+
3942
for addr in config.get('addrlist', '').split(','):
4043
if not addr:
4144
continue
@@ -67,9 +70,13 @@ def privilegedStartService(self):
6770
# Attaching CastFactory to ProcessorController
6871
self.tcpFactory.commit = self.ctrl.commit
6972

70-
self.tcp = self.reactor.listenTCP(0, self.tcpFactory,
73+
self.tcp = self.reactor.listenTCP(self.port, self.tcpFactory,
7174
interface=self.bind)
72-
self.tcp.startListening()
75+
try:
76+
self.tcp.startListening()
77+
except CannotListenError:
78+
pass # older Twisted required this.
79+
# newer Twisted errors. sigh...
7380

7481
# Find out which port is in use
7582
addr = self.tcp.getHost()
@@ -82,7 +89,8 @@ def privilegedStartService(self):
8289
udpaddrs=self.addrlist,
8390
period=self.annperiod)
8491

85-
self.udp = SharedUDP(0, self.udpProto, reactor=self.reactor)
92+
self.udp = SharedUDP(self.port, self.udpProto, reactor=self.reactor,
93+
interface=self.bind)
8694
self.udp.startListening()
8795

8896
# This will start up plugin Processors

0 commit comments

Comments
 (0)