Improve example code snippets
parent
acee746783
commit
4ba5c04e90
18
README.rst
18
README.rst
|
@ -47,6 +47,9 @@ Connecting to a remote I2P destination
|
||||||
data = await reader.read(4096)
|
data = await reader.read(4096)
|
||||||
print(data.decode())
|
print(data.decode())
|
||||||
|
|
||||||
|
# close the connection
|
||||||
|
writer.close()
|
||||||
|
|
||||||
# run event loop
|
# run event loop
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(connect_test("dummy.i2p"))
|
loop.run_until_complete(connect_test("dummy.i2p"))
|
||||||
|
@ -70,19 +73,18 @@ Accept connections in I2P
|
||||||
reader, writer = await i2plib.stream_accept(session_name)
|
reader, writer = await i2plib.stream_accept(session_name)
|
||||||
|
|
||||||
# first string on a client connection always contains clients I2P destination
|
# first string on a client connection always contains clients I2P destination
|
||||||
incoming = await reader.read(4096)
|
dest = await reader.readline()
|
||||||
dest, data = incoming.split(b"\n", 1)
|
remote_destination = i2plib.Destination(dest.decode().strip())
|
||||||
remote_destination = i2plib.Destination(dest.decode())
|
|
||||||
|
|
||||||
# destination and data may come in one chunck, if not - we wait for the actual
|
# read for the actual incoming data from the client
|
||||||
# incoming data
|
data = await reader.read(4096)
|
||||||
if not data:
|
|
||||||
data = await reader.read(4096)
|
|
||||||
|
|
||||||
print(data.decode())
|
print(data.decode())
|
||||||
|
|
||||||
# send data to the client
|
# send data back
|
||||||
writer.write(b"PONG")
|
writer.write(b"PONG")
|
||||||
|
|
||||||
|
# close the connection
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|
||||||
# run event loop
|
# run event loop
|
||||||
|
|
|
@ -37,6 +37,9 @@ Connecting to a remote I2P destination
|
||||||
data = await reader.read(4096)
|
data = await reader.read(4096)
|
||||||
print(data.decode())
|
print(data.decode())
|
||||||
|
|
||||||
|
# close the connection
|
||||||
|
writer.close()
|
||||||
|
|
||||||
# run event loop
|
# run event loop
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(connect_test("dummy.i2p"))
|
loop.run_until_complete(connect_test("dummy.i2p"))
|
||||||
|
@ -60,19 +63,18 @@ Accept connections in I2P
|
||||||
reader, writer = await i2plib.stream_accept(session_name)
|
reader, writer = await i2plib.stream_accept(session_name)
|
||||||
|
|
||||||
# first string on a client connection always contains clients I2P destination
|
# first string on a client connection always contains clients I2P destination
|
||||||
incoming = await reader.read(4096)
|
dest = await reader.readline()
|
||||||
dest, data = incoming.split(b"\n", 1)
|
remote_destination = i2plib.Destination(dest.decode().strip())
|
||||||
remote_destination = i2plib.Destination(dest.decode())
|
|
||||||
|
|
||||||
# destination and data may come in one chunck, if not - we wait for the actual
|
# read for the actual incoming data from the client
|
||||||
# incoming data
|
data = await reader.read(4096)
|
||||||
if not data:
|
|
||||||
data = await reader.read(4096)
|
|
||||||
|
|
||||||
print(data.decode())
|
print(data.decode())
|
||||||
|
|
||||||
# send data to the client
|
# send data back
|
||||||
writer.write(b"PONG")
|
writer.write(b"PONG")
|
||||||
|
|
||||||
|
# close the connection
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|
||||||
# run event loop
|
# run event loop
|
||||||
|
|
Loading…
Reference in New Issue