[Tutor] Fwd: asyncore and SocketServer

jovoslav@dir.bg jovoslav@dir.bg
Mon, 19 Mar 2001 23:54:02 +0200


This is a multi-part MIME message

--_===20031056====dir.bg===_
Content-Type: text/plain; charset="windows-1251"
Content-Transfer-Encoding: 8bit

--- sledva prepratenoto s"obschenie ---
-----------------------------
Free mail from www.dir.bg!

--_===20031056====dir.bg===_
Content-Type: message/rfc822

From: <jovoslav@dir.bg>
Subject: asyncore and SocketServer
To: tutor@python.org
X-Mailer: CommuniGate Pro Web Mailer v.3.4.1
Date: Fri, 16 Mar 2001 08:49:25 +0200
Message-ID: <web-19853586@dir.bg>
MIME-Version: 1.0
Content-Type: text/plain; charset="windows-1251"
Content-Transfer-Encoding: 8bit

Hello,
Now it's so. I'm new to python and as a small project I started
writing a small chat server ( for LAN ). My first spurce code looked
like this:
>>> import socket
>>> host = ''
>>> port = 3000
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.bind((host, port))
>>> s.listen(5)    " so far so good "
>>> conn, addr = s.accept()
>>> while 1:
>>>       send_data = raw_input('kiligarikond > ') " a kind of nickname
"
>>>       conn.send(send_data)
>>>       recv_data = conn.recv(1024) " for example "
>>>       print 'sunay > ', recv_data
END

OK, It run well but everything run synchronously. That was the problem.
The user had to make a request and when it came on the other side, the
other user was on turn.

The second try was ( after examining the asyncore module documentation
):

>>> import socket
>>> import asyncore
>>> class server(asyncore.dispatcher):
>>>      def __init__(self):
...              host = ''
...              port = 3000
...              asyncore.dispatcher.__init__(self)
...              self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
...              self.bind((host, port))
...              self.listen(5)
...              self.accept()
...
>>> serv = server()
>>>

Now the problem. :

I made my program recieving incoming connections asynchronously.
But I made only this.
I would be very greatfull if someone could tell me how to write
the other sections of the program. Or if someone could tell me an online
book about network programming in python.
Or, just tell me the URL where I can find some usefull examples.
Thanks very much :)                J O V O !!! :^)
-----------------------------
Free mail from www.dir.bg!

--_===20031056====dir.bg===_--