From: <umg...@us...> - 2007-06-20 15:07:37
|
Revision: 428 http://svn.sourceforge.net/pybridge/?rev=428&view=rev Author: umgangee Date: 2007-06-20 08:07:38 -0700 (Wed, 20 Jun 2007) Log Message: ----------- Add code to determine when loss of connection is expected (disconnection) and when the connection is severed unexpectedly (network failure). Modified Paths: -------------- trunk/pybridge/pybridge/network/client.py Modified: trunk/pybridge/pybridge/network/client.py =================================================================== --- trunk/pybridge/pybridge/network/client.py 2007-06-20 15:04:58 UTC (rev 427) +++ trunk/pybridge/pybridge/network/client.py 2007-06-20 15:07:38 UTC (rev 428) @@ -48,6 +48,8 @@ self.factory = pb.PBClientFactory() self.factory.clientConnectionLost = self.connectionLost + self.expectLoseConnection = False # Indicates when disconnecting. + self.username = None self.tables = {} # Tables observed. self.tableRoster = None @@ -61,11 +63,17 @@ self.tables.clear() self.tableRoster.clear() self.userRoster.clear() + self.username = None - print "Lost connection: %s" % reason.getErrorMessage() - self.notify('connectionLost', reason=reason.getErrorMessage()) + self.notify('loggedOut') + if not self.expectLoseConnection: + # Connection lost unexpectedly, so notify user. + print "Lost connection: %s" % reason.getErrorMessage() + self.notify('connectionLost', host=connector.host, + port=connector.port) + def errback(self, failure): print "Error: %s" % failure.getErrorMessage() @@ -89,17 +97,21 @@ # Methods - def connect(self, hostname, port): + def connect(self, host, port): """Connect to server. - @param hostname: - @param port: + @param host: the host name or IP address of the server. + @type host: string + @param port: the port number on which the server is listening. + @type port: int """ - connector = reactor.connectTCP(hostname, port, self.factory) + connector = reactor.connectTCP(host, port, self.factory) + self.expectLoseConnection = False def disconnect(self): """Drops connection to server.""" + self.expectLoseConnection = True self.factory.disconnect() @@ -124,7 +136,7 @@ """Actions to perform when connection succeeds.""" self.avatar = avatar self.username = username - self.notify('connectedAsUser', username=username) + self.notify('loggedIn', username=username) # Request services from server. for rostername in ['tables', 'users']: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |