[Twisted-Python] Plain windows sockets and twisted

Glyph Lefkowitz glyph at twistedmatrix.com
Sun Jan 17 19:52:19 EST 2010


On Jan 17, 2010, at 6:25 PM, Daniel Griffin wrote:

> I am using twisted in a cross-platform manner. I have written both the client and server. The client is twisted and the server uses python threads. I am using the select reactor and plain old TCP connections. I encode my messages to JSON to send them.
> 
> On Windows I get tons of un-clean connectionlost events, on Mac everything works perfectly. I am using the same data set in each case. 

You should use Twisted for your server and get rid of threads, or you should very carefully read <http://itamarst.org/writings/win32sockets.html> and understand the differences between what windows calls "sockets" and what the rest of the world does.

> If I use the threaded server on windows and the twisted client on mac then I still get tons of errors. 99% of these times these errors happen after the last dataReceived when the socket should be closed cleanly. 
 .
 .
 .
> 
> Is this the correct behavior for using plain sockets with twisted? Any reason why this would be perfectly fine on OSX and not Windows? Sorry for the long email. 

You'll need to give some more detail.  What errors are you seeing?  Please post a complete traceback, along with enough code to actually trigger the error.  (<http://sscce.org/> is a good resource explaining desirable attributes of such an example.)

What version of Twisted are you using?  What version of Python?  What is the protocol?  Are the errors occurring in your threaded server or your twisted client?

The quick answer to your question is: no, this behavior is not expected.  Sockets are sockets.  Twisted should work fine talking to sockets in threads, sockets in other programming languages, other operating systems, etc.  Of course, that's just what's *supposed* to happen: there's a bug here, and with the information I have now, I can't say whether it's in your threaded code, your Twisted code, Twisted, or even Python.

Good luck?





More information about the Twisted-Python mailing list