You can build a client in Python if you feel like it, but you might as well just use telnet
:
$ telnet localhost 9877
import asyncio | |
clients = {} | |
async def handle_new_client(reader, writer): | |
writer.write("Welcome to our server!\n".encode('utf-8')) | |
peername = '{}:{}'.format(*writer.get_extra_info("peername")) | |
clients[peername] = reader, writer | |
while True: | |
b = await reader.readline() | |
if not b: | |
del clients[peername] | |
return | |
for r, w in clients.values(): | |
w.write("{}: {}".format(peername, b.decode('utf-8')).encode('utf-8')) | |
await w.drain() | |
loop = asyncio.get_event_loop() | |
server = loop.run_until_complete(asyncio.start_server(handle_new_client, "", 9877)) | |
loop.run_forever() |