socket programming

Josh Close narshe at gmail.com
Wed Sep 15 12:57:15 EDT 2004


Use asynchore/asynchat modules. They will do all that stuff for you.

http://docs.python.org/lib/module-asyncore.html
http://docs.python.org/lib/module-asynchat.html

-Josh


On Thu, 16 Sep 2004 02:49:13 +1000, Ajay <abra9823 at mail.usyd.edu.au> wrote:
> hi!
> 
> on my client side, i have a socket that sends and then receives
> the code is
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((PDA_ADDRESS, PDA_PORT))
> s.send("persona=")
> s.send(persona)
> s.send("\n")
> str = s.recv(1024)
> data=""
> while len(str) != 0:
>         data += str
>         str = s.recv(1024)
> print data
> 
> on my server side i create the serversocket, listen, get the client socket
> and the client socket receives the data as follows
> (clientsocket, address) = serversocket.accept()
> str = clientsocket.recv(256)
> data=""
> while len(str) != 0:
>         data += str
>         str = clientsocket.recv(256)
> 
> the problem is when my client finished sending and waits to receive, on the
> server side, it still stays in the while loop waiting to receive more data.
> 
> how do i stop that?
> 
> thanks
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list