27 |
27 |
28 def __init__(self, address, parent=None): |
28 def __init__(self, address, parent=None): |
29 """ |
29 """ |
30 Constructor |
30 Constructor |
31 |
31 |
32 @param address address the server should listen on (QHostAddress) |
32 @param address address the server should listen on |
33 @param parent reference to the parent object (QObject) |
33 @type QHostAddress |
|
34 @param parent reference to the parent object |
|
35 @type QObject |
34 """ |
36 """ |
35 super().__init__(parent) |
37 super().__init__(parent) |
36 |
38 |
37 self.__address = address |
39 self.__address = address |
38 |
40 |
39 def incomingConnection(self, socketDescriptor): |
41 def incomingConnection(self, socketDescriptor): |
40 """ |
42 """ |
41 Public method handling an incoming connection. |
43 Public method handling an incoming connection. |
42 |
44 |
43 @param socketDescriptor native socket descriptor (integer) |
45 @param socketDescriptor native socket descriptor |
|
46 @type int |
44 """ |
47 """ |
45 connection = Connection(self) |
48 connection = Connection(self) |
46 connection.setSocketDescriptor(socketDescriptor) |
49 connection.setSocketDescriptor(socketDescriptor) |
47 self.newConnection.emit(connection) |
50 self.newConnection.emit(connection) |
48 |
51 |
49 def startListening(self, port=-1, findFreePort=False): |
52 def startListening(self, port=-1, findFreePort=False): |
50 """ |
53 """ |
51 Public method to start listening for new connections. |
54 Public method to start listening for new connections. |
52 |
55 |
53 @param port port to listen on (integer) |
56 @param port port to listen on |
|
57 @type int |
54 @param findFreePort flag indicating to search for a free port |
58 @param findFreePort flag indicating to search for a free port |
55 depending on the configuration (boolean) |
59 depending on the configuration |
56 @return tuple giving a flag indicating success (boolean) and |
60 @type bool |
57 the port the server listens on |
61 @return tuple giving a flag indicating success and the port the |
|
62 server listens on |
|
63 @rtype tuple of (bool, int) |
58 """ |
64 """ |
59 res = self.listen(self.__address, port) |
65 res = self.listen(self.__address, port) |
60 if findFreePort and Preferences.getCooperation("TryOtherPorts"): |
66 if findFreePort and Preferences.getCooperation("TryOtherPorts"): |
61 endPort = port + Preferences.getCooperation("MaxPortsToTry") |
67 endPort = port + Preferences.getCooperation("MaxPortsToTry") |
62 while not res and port < endPort: |
68 while not res and port < endPort: |