[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] network



On Mon, 28 Jun 2004, Pete Shinners wrote:

> Jasper Phillips wrote:
> > Besides, what other alternative is there?  Python's socket module?!
> 
> I'm just curious on this one. I've never done any network programming 
> farther than testing a connection and passing a string or two back and 
> forth. I've heard people say that socket level programming is bad, but 
> never the reasons why.

Socket programming is tedious, error prone, hard to test, and other people
have already done it.  There is also much more to it than passing a string
or two.  IMHO it is the equivalent of maintaining your own list and
dictionary code in Python.  Can I do it?  Sure.  Do I have time to do it?
No.


> I've read code that uses both sockets and twisted, and personally, the 
> vanilla sockets always looks like a win to me. The benefit of twisted is 
> that it supports about every protocol in use. But if you are just going 
> to be passing your own message types over the socket, why bother?

The ability to pass objects, and smoothly access them remotely.  Callbacks
and the event model in general.  Remote error handling.  Security.
Robustness.  Twisted is widely tested by others.  Perspective Broker already
handles many of the details you will need.  Easy to switch to SSH.

I completely fail to see why vanilla sockets look like a win to you.  In
fact I see no advantage at all.  Perhaps I'm missing something?


> When you say you prefer twisted, how are you using it? Isn't it just 
> some tool for "send a message", "has a message arrived"? How is that 
> better than socket with select? Or if you need, the asyncore module has 
> already tied those together for you.

Twisted lets me avoid dealing with low level details, minimizing the amount
I have to deal with network code and isolating it too.  I can send objects
and access them remotely with ease, and it just works.

Compare this to a game similar to mine (Dominion 2), which handles sockets
directly and has all sorts of networking problems -- I've put in less effort
and yet have less problems.


> The Twisted documentation I've read starts like "you don't write 
> applications that use twisted, you write libraries that plugin to it".

Well, you don't have to actually use Twisted this way.  However to be frank
the approach they recommend is the correct one, it just seems to be a new
style of programming for many people.  I'd no more use non-event based
networking code than I'd use a non-event based GUI toolkit.


> Personally, I still intend to use sockets at some point when I add 
> networking to a game. :]

Go for it.  It's worked for many others, and I see no reason it can't work
for you.  Besides, my impression is that you like low level programming. ;-)

-Jasper