mirror of https://github.com/python/cpython.git
After testing the test on Unix, several improvements:
- Use push() instead of send(), and make these calls in main(). - Sleep a second to give the server thread time to initialize itself.
This commit is contained in:
parent
66172520ee
commit
dca060c55c
|
@ -1,6 +1,6 @@
|
||||||
# test asynchat -- requires threading
|
# test asynchat -- requires threading
|
||||||
|
|
||||||
import asyncore, asynchat, socket, threading
|
import asyncore, asynchat, socket, threading, time
|
||||||
|
|
||||||
HOST = "127.0.0.1"
|
HOST = "127.0.0.1"
|
||||||
PORT = 54321
|
PORT = 54321
|
||||||
|
@ -32,8 +32,6 @@ def __init__(self):
|
||||||
self.connect((HOST, PORT))
|
self.connect((HOST, PORT))
|
||||||
self.set_terminator("\n")
|
self.set_terminator("\n")
|
||||||
self.buffer = ""
|
self.buffer = ""
|
||||||
self.send("hello ")
|
|
||||||
self.send("world\n")
|
|
||||||
|
|
||||||
def handle_connect(self):
|
def handle_connect(self):
|
||||||
print "Connected"
|
print "Connected"
|
||||||
|
@ -49,7 +47,10 @@ def found_terminator(self):
|
||||||
def main():
|
def main():
|
||||||
s = echo_server()
|
s = echo_server()
|
||||||
s.start()
|
s.start()
|
||||||
|
time.sleep(1) # Give server time to initialize
|
||||||
c = echo_client()
|
c = echo_client()
|
||||||
|
c.push("hello ")
|
||||||
|
c.push("world\n")
|
||||||
asyncore.loop()
|
asyncore.loop()
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue