- Use push() instead of send(), and make these calls in main().
- Sleep a second to give the server thread time to initialize itself.
# test asynchat -- requires threading
-import asyncore, asynchat, socket, threading
+import asyncore, asynchat, socket, threading, time
HOST = "127.0.0.1"
PORT = 54321
self.connect((HOST, PORT))
self.set_terminator("\n")
self.buffer = ""
- self.send("hello ")
- self.send("world\n")
def handle_connect(self):
print "Connected"
def main():
s = echo_server()
s.start()
+ time.sleep(1) # Give server time to initialize
c = echo_client()
+ c.push("hello ")
+ c.push("world\n")
asyncore.loop()
main()