[Twisted-web] sendLine and connectionLost question

DAVID JIMENEZ CARRASCO djimenez at unipost.es
Thu May 27 02:42:02 EDT 2010


Hi Jean Paul,

A lot of thanks for your quick answer. It's really appreciated. Regarding your answer, I understand that when the remote hosts stop responding, after a timer, the connection is considered lost. But the main problem is that the remaining client (the one that have not been disconnected) should continue working without problems and the fact is that the server closes connection to that client too in a "non clean fashion".

Regards and a lot of thanks for your help,

David

De: twisted-web-bounces at twistedmatrix.com [twisted-web-bounces at twistedmatrix.com] En nombre de exarkun at twistedmatrix.com [exarkun at twistedmatrix.com]
Enviado el: jueves, 27 de mayo de 2010 3:38
Para: Twisted Web World
Asunto: Re: [Twisted-web] sendLine and connectionLost question

On 26 May, 10:46 pm, djimenez at unipost.es wrote:
>Hi all,
>
>I'm trying to write a typical chat server application with twisted. At
>this moment, all is working fine except for some strange behaviour with
>sendLine and connectionLost funcs. Let me explain the problem:
>
>- I have a server on the internet.
>- I connect two PCs (2 clients) from the same LAN through a router to
>that server
>- All is working fine until I disconnect the LAN of one of those PC
>(The client is disconnected but the server doesn't know about it). Just
>to test a typical wireless disconnection without closing sockets,
>etc...
>- After disconnecting I try to send some messages through the remaining
>clients to all clients through this function:
>
>    def sendMessageToAllClients(self, mesg,reqClient):
>        for client in self.clientProtocols:
>            dataLength = str(len(mesg))
>            if (len(dataLength) < 8):
>                dif = 8 - len(dataLength)
>                dataLength = "0"*dif + dataLength
>            print "Enviando a:",str(client)
>            client.sendLine(dataLength+mesg)
>            client.clearLineBuffer()

You shouldn't be calling `client.clearLineBuffer()` here.
>
>As you can see, I send a message to all clients, including the one
>disconnected because the server doesn't
>know at this moment that the client is "out". I'm able to send 6 or 7
>messages to the remaining client but
>after that, the connection get lost. I would expect to have a
>connectionLost with the client offline but actually
>I got a connectionLost in both clients and I don't know why. The server
>disconnect both clients with "non clean fashion".
>
>Any help or advice would be highly appreciated.

This is how TCP works.  If the remote host stops responding to packets,
then there's a period of time where the connection still appears to be
up anyway.  After a TCP-level timer expires, the connection is
considered lost.

Jean-Paul

_______________________________________________
Twisted-web mailing list
Twisted-web at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
------------------------------------------------------------------------------------------------------------------------------------------------
Este mensaje es confidencial y atañe exclusivamente a las personas a las que va dirigido.
Cualquier opinión en el contenida, es exclusivo de su autor y no representa necesariamente
la opinion de UNIPOST, S.A.
Si Ud. no es el destinatario del  mensaje, considerese advertido que lo ha recibido por error
y que cualquier difusión o copia estan terminantemente prohibidos. Si ha recibido por error, 
por favor comuniquelo a UNIPOST, S.A. al número +34 93 223 25 52 o correo electrónico 
a <support at unipost.es>.

This e-mail is confidential and intended solely for the use of the individual to whom it is addressed.
Any opinions presented are solely those of the author and do not necessarily represent those of 
UNIPOST, S.A.
If you are not the intended recipient, be advised that you have received this e-mail in error and that 
dissemination, forwarding or copying of this e-mail is strictly prohibited. If you have received this 
e-mail in error please notify it to UNIPOST, S.A. by telephone on number +34 93 223 25 52 or by
e-mail to <support at unipost.es>.
------------------------------------------------------------------------------------------------------------------------------------------------



More information about the Twisted-web mailing list