Save working code
This commit is contained in:
parent
0dc500c541
commit
28dc842103
|
@ -31,8 +31,7 @@ async def write_data(stream):
|
|||
|
||||
|
||||
async def run(port, destination):
|
||||
external_ip = urllib.request.urlopen(
|
||||
'https://v4.ident.me/').read().decode('utf8')
|
||||
external_ip = "192.168.1.39"
|
||||
transport_opt_str = "/ip4/%s/tcp/%s" % (external_ip, port)
|
||||
host = await new_node(
|
||||
transport_opt=[transport_opt_str])
|
||||
|
|
|
@ -41,10 +41,16 @@ async def main():
|
|||
|
||||
# Convert neighbor_addr_str to multiaddr
|
||||
neighbor_addr = multiaddr.Multiaddr(neighbor_addr_str)
|
||||
print("Connecting")
|
||||
await connect(node.libp2p_node, neighbor_addr)
|
||||
await asyncio.sleep(5)
|
||||
print("Creating new stream")
|
||||
s = await node.libp2p_node.new_stream(id_opt, ["/foo/1"])
|
||||
await s.write("foo".encode())
|
||||
await asyncio.sleep(15)
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
loop.close()
|
||||
# loop.run_until_complete(main())
|
||||
asyncio.ensure_future(main())
|
||||
loop.run_forever()
|
||||
# loop.close()
|
||||
|
|
Loading…
Reference in New Issue
Block a user