3

Which way is better?

Creating a while loop and then using the select module OR using ThreadedTCPServer with a custom class.

Im having problems with the Threaded TCP Server, although it could just be my coding.

asked Jul 14, 2011 at 21:06
5
  • Better by what criteria? Commented Jul 14, 2011 at 21:08
  • Well, what is the general method. Commented Jul 14, 2011 at 21:08
  • I thought while loops are bad, but then again it seems to be working better than the "python approved" method. Commented Jul 14, 2011 at 21:09
  • What kind of server? HTTP/web, or lower-level TCP? You're almost certainly best off not writing your own, because you'll be debugging problems others have already found solutions for. What kinds of problems are you having with ThreadedTCPServer? Commented Jul 14, 2011 at 21:27
  • Very slow, sluggish, when i do a keyboardinterrupt it will hang for anywhere up to 5 minutes (there are known problems, that i found on google with this apparently) Also forgot to say, low level TCP Commented Jul 14, 2011 at 21:45

2 Answers 2

5

My personal recommendation is to use Twisted. It's a Python-based framework intended primarily for writing event-driven network software. The documentation has a lot of great examples of how to create various types of servers and clients, as well.

answered Jul 14, 2011 at 21:19
Sign up to request clarification or add additional context in comments.

1 Comment

While Twisted is not necessarily the end-all be-all solution for everything, it's pretty tough to find something within its problem domain (concurrency, work distribution) that it can't do fairly well.
1

I am sure there is no such a thing like the "correct" way.

If you want not, must not or cannot use any of the existing server implementations the general idea is (in pseudo code):

ss = serversocket()
ss.bind ()
while (True):
 cs = ss.accept ()
 spawnCommThread (cs)

In the CommThread for each client you take care of reading from the socket returned by accept, communicate with your client and die, when the client closes the connection or another criterion is given.

answered Jul 14, 2011 at 21:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.