Created
May 30, 2011 02:14
-
-
Save mopemope/998365 to your computer and use it in GitHub Desktop.
tobikko example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tobikko import get_hub | |
from tobikko.api import * | |
from tobikko.server import StreamServer | |
from tobikko import socket | |
def test_accept(): | |
s = StreamServer() | |
def _handle(sock, addr): | |
while True: | |
d = sock.recv(10) | |
if not d: | |
break | |
print "server recv %s" % d | |
sock.sendall(d) | |
def client(): | |
hub = get_hub() | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(("", 8000)) | |
s.sendall("A" * 10) | |
print "recv %s" % s.recv(10) | |
s.sendall("B" * 10) | |
print "recv %s" % s.recv(10) | |
sleep(1) | |
print "abort" | |
hub.abort() | |
start_thread_later(client, 1) | |
s.add_listener(("0.0.0.0", 8000), _handle) | |
s.serve_forever() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment