Sockets in Python

Wayne Izatt wayne.izatt at _nospam_myself.com
Fri Mar 23 06:46:07 CET 2001


> here is my problem : I'd like to create a simple network card game with
> Python,

sound like fun

> but I've got some troubles with the sockets...

ok

> In fact I'd like to find some kind of tutorial about this subject, because
> although
> my first-time code quite works, I don't think it is really good.
>
> When I try all the samples I've found on the 'net about sockets, the
"main"
> loop for communicating, generally implemented with a While 1: ..., makes
my
> computer frozen up (under Windows, not under Linux).
> That's why I thought it would be better to use threads, for the listening
> function
> for example, but it doesn't work well under Windows (sometimes it hangs
up,
> I can't figure out why !).

nor can I, since I can't see your code

> I'm sure it's possible creating a robust and nice app which uses the
> sockets encapsulation provided with Python under Windows, but how ?

Python sockets are the easiest I've used. However, I think it can be useful
to
know a little bit more about socket programming than what one normally gets
from a Python or Perl or whatever tutorial. Even reading through some of the
C-based tutorials will help (if not, at least it'll make you grateful you
get to use the
Python socket API rather than the raw C API). I'm not saying you have to
digest Stephens completely, but I've seen aome pretty good intros for linux
programmers. If you can't find one, let me know and I'll dig a little.

> What are the "good" things to do ?

Whatever gets the job done. Socket programming is easy and difficult - easy
to get something up and running, difficult to get working perfectly.

> What is the best module to use between socket or asyncore ?

asyncore allows you to avoid threads. I don't know why anyone would want
to avoid threads, especially Python threads.

> Well, if someone can help me with the sockets in general and the sockets
> with Python, it would be greatly appreciated...
> (I've already read the "classic" tutorials about sockets, I followed the
> links
> on the Python website, etc..)

As I said, I think the C tuts are pretty good (just so you know what's going
on
under the hood). The socket programming chapters in the 2nd edition of
Programming Python (Lutz) are particularly excellent - I wish I'd had them
years ago. Look in the Google directory for good, oatsy socket stuff. Post
the
problem sections of your code, or send them and I'll take a look.

cheers

>
> Thanks in advance.
>
>
>
>
>
>
>





More information about the Python-list mailing list