On 26 May, 10:46 pm, [email protected] 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 [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
