[Twisted-Python] Another tcp.Client question
Glyph Lefkowitz
glyph at twistedmatrix.com
Mon Sep 3 00:01:16 MDT 2001
On Mon, Sep 03, 2001 at 12:57:31AM +0200, Benjamin Bruheim wrote:
> yes, it shall accept one connection, and after the transfer is done, it shall
> close the connection (and in this way tell the user that the transfer is
> done). it shall let the tcp time-out, and that's why we change the port; less
> time is wasted between each new file. I am thinking of letting the user
> define a range of ports, and cycle through that instead of using port 0.
OK. That isn't really happening. :-)
> > You have committed it. Still: I see no loseConnection being called on a
> > *Port*, only on a *Server*, which is a connection that got accepted from a
> > port.
>
> Isn't 'self.dtpPort = tcp.Port(0, self)' a Port?
Yes.
> self.dtp.transport is self.dtpPort,
No.
> and its method loseConnection is used.
Yes, for some values of "its" :-)
> Besides, isn't Port the same as a server?
No.
Here's the deal -- tcp.Port creates a _listening socket on a port_. That
_listening socket on a Port_ creates a _Server connection_; the class Server
represents the byte-stream connection socket, the class Port represents the
listening on a port socket. Servers are created by a Port.
self.dtp.transport is a twisted.internet.tcp.Server; self.dtpPort is a
twisted.internet.tcp.Port (repr 'em sometime ^_^). Both must have their
connections lost, at different points.
Port.loseConnection() will cause the socket to stop listening.
Server.loseConnection() will cause that particular connection to be closed.
Port.loseConnection should probably happen in the buildProtocol method of your
ProtocolFactory, since it's explicitly only ever supposed to accept one
connection.
Does this make more sense?
> > Yes, and my point is that, as far as I understand FTP, you *should* be
> > exercising that code. I still don't understand why you're not.
>
> Well, if I could. And how come nobody ever have run into that removeReader
> with an NameError or something?
Itamar says he did, I think. I sure did, when I tried it. That particular
path of code was never exercised -- although hopefully it will be in FTP fairly
soon. twisted.protocols.ftp was never calling it, only Server.loseConnection,
which is the source of most of your current troubles, I believe.
--
______ __ __ _____ _ _
| ____ | \_/ |_____] |_____|
|_____| |_____ | | | |
@ t w i s t e d m a t r i x . c o m
http://twistedmatrix.com/users/glyph
More information about the Twisted-Python
mailing list