Basic client/server with sockets

Steve Holden sholden at holdenweb.com
Tue Feb 11 05:24:40 CET 2003


"Andrew Bennetts" <andrew-pythonlist at puzzling.org> wrote in message
news:mailman.1044927282.26166.python-list at python.org...
> On Tue, Feb 11, 2003 at 01:27:11AM +0100, Irmen de Jong wrote:
> > Andrew Bennetts wrote:
> > >On Mon, Feb 10, 2003 at 02:10:35PM -0800, Natan wrote:
> > >
> > >>I'm new to python ans i have a script like this:
> > >
> > >
> > >I recommend writing your server using Twisted
<http://twistedmatrix.com> --
> > >it will take care of problems like this for you, leaving you to worry
about
> > >the logic of your protocol, rather than the details of the socket API.
> >
> > When using Pyro (http://pyro.sourceforge.net) you don't even
> > have to worry about the protocol ;-)
>
> Well, ditto with Twisted ;)
>
> It not only implements many common protocols for you (HTTP, POP, SMTP,
SSH,
> FTP, ...), it has its own remote object protocol (Perspective Broker) :)
>
> I strongly recommend taking a look, if you haven't already.
>

How quickly this thread got off-topic! I might equally well suggest that
everybody buys "Python Web Programming" to help them build their systems,
but that doesn't answer the question ...

The real answer is quite simple, however: the protocol deadlocks in the face
of zero-length data. Suppose you just hit return to the client: the "input"
variable (not a terribly good name, by the way, since it's also the name of
a built-in function) receives a zero-length string. So the "s.send(input)"
sends zero bytes - easily done, you don't actually need a network interface
for that :-).

Unfortunately, the server doesn't receive anything - hardly surprising,
since the client just explicitly didn't send anything. So now you have a
server that's still waiting for the client to send it something, and a
client that won't send anything else until it receives back the empty string
it just sent (not) to the server. Result: deadlock.

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Register for PyCon now!            http://www.python.org/pycon/reg.html







More information about the Python-list mailing list