def _httpClient():
    HOST = '127.0.0.1'
    PORT = 8080

    try:
        sock = Socket.tcpClient(HOST, PORT)
    except Exception as e:
        print 'Connection Failure', e
        yield
        return

    try:
        yield sock.send('GET / 1.1\r\n')
        yield sock.send('Host: %s\r\n' % HOST)
        yield sock.send('\r\n\r\n')

        while 1:
            buf = yield sock.recv()
            if not buf:
                break

            sys.stdout.write(buf)
    except Exception as e:
        print 'Client Failure', e

    sys.stdout.write('\n')
    yield sock.close()

    coreasync.stop()
def clientLoop():
    BUFSIZE = 8 * 1024
    HOST = '127.0.0.1'
    PORT = 7550
    COUNT = 4 * 1024

    KB = 1024
    MB = 1024 * KB

    testdata = 'x' * (BUFSIZE-1) + '\n'
    testdata_len = len(testdata)

    socket = coreasync.Socket.tcpClient(HOST, PORT)

    t1 = time.time()
    i = 0
    while i < COUNT:
        yield socket.send(testdata)

        x = 0
        while x < testdata_len:
            buf = yield socket.recv(BUFSIZE)
            if not buf:
                break
            x += len(buf)
        i += 1
    t2 = time.time()

    yield socket.close()

    print 'Total:', t2-t1
    print 'Throughput:', round((float(BUFSIZE*COUNT) / MB) / (t2-t1), 3), 'Mb/sec.'

    coreasync.stop()
def readFile():
    fd = coreasync.File(filename='test-file.py', mode='r')
    while True:
        buf = yield fd.read(128)
        if not buf:
            break
        print buf,
    yield fd.close()

    coreasync.stop()