コード例 #1
0
async def async_socket(req):
    # Create the socket using Pythons built-in socket class.
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # Set it to nonblocking.
    sock.setblocking(False)

    # Create a kore.socket with kore.socket_wrap().
    conn = kore.socket_wrap(sock)

    # Asynchronously connect to 127.0.0.1 port 8888
    await conn.connect("127.0.0.1", 8888)
    kore.log(kore.LOG_INFO, "connected!")

    # Now send the GET request
    msg = "GET /socket-test HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"
    await conn.send(msg.encode())
    kore.log(kore.LOG_INFO, "request sent!")

    # Read the response.
    data = await conn.recv(8192)
    kore.log(kore.LOG_INFO, "got response!")

    # Respond with the response from /socket-test.
    req.response(200, data)

    conn.close()
コード例 #2
0
ファイル: async_socket.py プロジェクト: jorisvink/kore
async def async_socket(req):
    # Create the socket using Pythons built-in socket class.
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # Set it to nonblocking.
    sock.setblocking(False)

    # Create a kore.socket with kore.socket_wrap().
    conn = kore.socket_wrap(sock)

    # Asynchronously connect to 127.0.0.1 port 8888
    await conn.connect("127.0.0.1", 8888)
    kore.log(kore.LOG_INFO, "connected!")

    # Now send the GET request
    msg = "GET /socket-test HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"
    await conn.send(msg.encode())
    kore.log(kore.LOG_INFO, "request sent!")

    # Read the response.
    data = await conn.recv(8192)
    kore.log(kore.LOG_INFO, "got response!")

    # Respond with the response from /socket-test.
    req.response(200, data)

    # Close the underlying socket, no need to close the wrapped kore.socket
    sock.close()
コード例 #3
0
ファイル: echo.py プロジェクト: ypgsh/kore
    def __init__(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setblocking(False)
        sock.bind(("127.0.0.1", 6969))
        sock.listen()

        self.conn = kore.socket_wrap(sock)
コード例 #4
0
ファイル: echo.py プロジェクト: jorisvink/kore
    def __init__(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setblocking(False)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(("127.0.0.1", 6969))
        sock.listen()

        self.conn = kore.socket_wrap(sock)