[Twisted-Python] XMPP server connection question
Hello everyone, I wrote an XMPP client and I have a question, when it tries to connect and the server is not listening, it doesn't send back an error and tries forever. I see that this function (twisted/names/srvconnect.py): def _ebGotServers(self, failure): failure.trap(DNSNameError) # Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback. self.servers = [] self.orderedServers = [] traps the exception so it never propagates to me, so I can't handle it. Any ideas? I using the XMPP client example as a base for my code. Thank you, Gabriel
Gabriel Rossetti wrote:
Hello everyone,
I wrote an XMPP client and I have a question, when it tries to connect and the server is not listening, it doesn't send back an error and tries forever. I see that this function (twisted/names/srvconnect.py):
def _ebGotServers(self, failure): failure.trap(DNSNameError)
# Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback.
self.servers = [] self.orderedServers = []
traps the exception so it never propagates to me, so I can't handle it. Any ideas? I using the XMPP client example as a base for my code.
Thank you, Gabriel Ok, the code I showed has nothing to do with the problem I think, what I don't get is the client never returns an error if nobody's listening...
Best regards, Gabriel
On Tue, Dec 2, 2008 at 8:21 AM, Gabriel Rossetti < gabriel.rossetti@arimaz.com> wrote:
Gabriel Rossetti wrote:
Hello everyone,
I wrote an XMPP client and I have a question, when it tries to connect and the server is not listening, it doesn't send back an error and tries forever. I see that this function (twisted/names/srvconnect.py):
def _ebGotServers(self, failure): failure.trap(DNSNameError)
# Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback.
self.servers = [] self.orderedServers = []
traps the exception so it never propagates to me, so I can't handle it. Any ideas? I using the XMPP client example as a base for my code.
Thank you, Gabriel
Ok, the code I showed has nothing to do with the problem I think, what I don't get is the client never returns an error if nobody's listening...
It may be better to show a log of what is happening.
It should show something like the following :
2008-12-02 08:57:01-0500 [-] reactor class:
twisted.internet.selectreactor.SelectReactor.
2008-12-02 08:57:01-0500 [-] Starting factory
Best regards,
Gabriel
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Christopher Zorn wrote:
On Tue, Dec 2, 2008 at 8:21 AM, Gabriel Rossetti
mailto:gabriel.rossetti@arimaz.com> wrote: Gabriel Rossetti wrote:
Hello everyone,
I wrote an XMPP client and I have a question, when it tries to connect and the server is not listening, it doesn't send back an error and tries forever. I see that this function (twisted/names/srvconnect.py):
def _ebGotServers(self, failure): failure.trap(DNSNameError)
# Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback.
self.servers = [] self.orderedServers = []
traps the exception so it never propagates to me, so I can't handle it. Any ideas? I using the XMPP client example as a base for my code.
Thank you, Gabriel
Ok, the code I showed has nothing to do with the problem I think, what I don't get is the client never returns an error if nobody's listening...
It may be better to show a log of what is happening.
Yeah, the t.w.p.j.xmlstream.XmlStreamFactory inherits from ReconnectingClientFactory, which is IMHO wrong. See also: http://twistedmatrix.com/trac/ticket/3492
Christopher Zorn wrote:
On Tue, Dec 2, 2008 at 8:21 AM, Gabriel Rossetti
mailto:gabriel.rossetti@arimaz.com> wrote: Gabriel Rossetti wrote:
Hello everyone,
I wrote an XMPP client and I have a question, when it tries to connect and the server is not listening, it doesn't send back an error and tries forever. I see that this function (twisted/names/srvconnect.py):
def _ebGotServers(self, failure): failure.trap(DNSNameError)
# Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback.
self.servers = [] self.orderedServers = []
traps the exception so it never propagates to me, so I can't handle it. Any ideas? I using the XMPP client example as a base for my code.
Thank you, Gabriel
Ok, the code I showed has nothing to do with the problem I think, what I don't get is the client never returns an error if nobody's listening...
It may be better to show a log of what is happening.
It should show something like the following :
2008-12-02 08:57:01-0500 [-] reactor class: twisted.internet.selectreactor.SelectReactor. 2008-12-02 08:57:01-0500 [-] Starting factory
2008-12-02 08:57:02-0500 [-] /etc/resolv.conf changed, reparsing 2008-12-02 08:57:02-0500 [-] Resolver added ('192.168.2.1 http://192.168.2.1', 53) to server list 2008-12-02 08:57:02-0500 [-] starting on 31847 2008-12-02 08:57:02-0500 [-] Starting protocol 2008-12-02 08:57:02-0500 [-] (Port 31847 Closed) 2008-12-02 08:57:02-0500 [-] Stopping protocol 2008-12-02 08:57:02-0500 [-] will retry in 2 seconds 2008-12-02 08:57:02-0500 [-] Stopping factory This will keep trying until you quit. You can set a limit on how many times it retries.
Best regards,
Gabriel
______________________
Ok, I finally created a class that wraps the client.XMPPClientFactory function and calls callbacks when the connection fails. Thanks
Phil Mayers wrote:
Christopher Zorn wrote:
On Tue, Dec 2, 2008 at 8:21 AM, Gabriel Rossetti
mailto:gabriel.rossetti@arimaz.com> wrote: Gabriel Rossetti wrote:
Hello everyone,
I wrote an XMPP client and I have a question, when it tries to connect and the server is not listening, it doesn't send back an error and tries forever. I see that this function (twisted/names/srvconnect.py):
def _ebGotServers(self, failure): failure.trap(DNSNameError)
# Some DNS servers reply with NXDOMAIN when in fact there are # just no SRV records for that domain. Act as if we just got an # empty response and use fallback.
self.servers = [] self.orderedServers = []
traps the exception so it never propagates to me, so I can't handle it. Any ideas? I using the XMPP client example as a base for my code.
Thank you, Gabriel
Ok, the code I showed has nothing to do with the problem I think, what I don't get is the client never returns an error if nobody's listening...
It may be better to show a log of what is happening.
Yeah, the t.w.p.j.xmlstream.XmlStreamFactory inherits from ReconnectingClientFactory, which is IMHO wrong.
See also:
Yes, so do I.
On 2008-12-05 11:42, Phil Mayers wrote:
Christopher Zorn wrote:
Yeah, the t.w.p.j.xmlstream.XmlStreamFactory inherits from ReconnectingClientFactory, which is IMHO wrong.
See also:
Wrong? It was just a design choice for this particular factory, made more than five years ago. Since then, the code has been refactored in such a way that it is pretty straightforward to have a non-reconnecting XMPP client: -----8<-----8<-----8<----- from twisted.words.xish.xmlstream import BootstrapMixin from twisted.internet import protocol class NonReconnectingXmlStreamFactory(BootstrapMixin, protocol.ClientFactory): """ XmlStream factory that connects at most once. @ivar authenticator: The authenticator to be associated with the XmlStream once a connection has been established. """ def __init__(self, authenticator): xmlstream.BootstrapMixin.__init__(self) self.authenticator = authenticator def buildProtocol(self, addr): """ Create an instance of XmlStream and associate the authenticator. """ xs = self.protocol(authenticator) self.installBootstraps(xs) return xs -----8<-----8<-----8<----- You can then also override protocol.ClientFactory's clientConnectionFailed and clientConnectionLost as desirable. You should probably add bootstrap handlers for STREAM_AUTHD_EVENT, INIT_FAILED_EVENT, STREAM_ERROR_EVENT somewhere. I have a similar special client factory in Wokkel that fires a deferred as soon as a connection was made and the stream is authenticated. See wokkel.client.DeferredClientFactory. ralphm
participants (4)
-
Christopher Zorn
-
Gabriel Rossetti
-
Phil Mayers
-
Ralph Meijer