# TCP Server inside Blender [closed]

I'm trying to implement a tcp server inside blender with a time operator using asyncio. but the code always crash the UI. I know there is a way to do this inside blender since some people have achieved it already...i found that blender cloud addon..can be the way to go but i don't know where to start any help???

This is the code im trying to mix with the blender cloud addon.. i think i need to integrate the async_loop.py file but i don't know how to start

import asyncio

message = data.decode()

print("Send: %r" % message)
writer.write(data)
await writer.drain()

print("Close the client socket")
writer.close()

loop = asyncio.get_event_loop()
coro = asyncio.start_server(handle_echo, '127.0.0.1', 8888, loop=loop)
server = loop.run_until_complete(coro)

# Serve requests until Ctrl+C is pressed
print('Serving on {}'.format(server.sockets[0].getsockname()))
try:
loop.run_forever()
except KeyboardInterrupt:
pass

# Close the server
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()


right now the code im using is by creating a file and reading it with a time operator like it is described here

send instructions to blender from external application

• Since you don't post any code nor details about the crash, there is little we can tell about your situation. You could take a look at how I integrated asyncio with the Blender Cloud add-on. – dr. Sybren Jul 7 '17 at 23:47
• Hi, @dr.Sybren, sorry about that... i found the blender cloud add-on but im still relatively new to python so im trying to understand the code....i updated my question so you can understand better my issue – Ymmanuel Jul 8 '17 at 3:32

loop.run_forever() will make your script block Blender itself. You have to call loop.stop() before that, so that run_forever() will only do a single iteration over the asyncio tasks that can be run at that time. Calling this single iteration then has to be performed frequently. This is what the asyncio.loop modal operator is for.