socket.sendall writes a byte message to the connected client. Paired with recv, it gives a socket application both directions of communication. section 3.2 section 3.2.1
Echo the received message
After receiving bytes into buffer, call connection.sendall(buffer). A Telnet client that sends testing123 followed by a line ending then receives the same message, creating a basic echo server. section 3.2.1
while buffer[-2:] != b'\r\n':
data = connection.recv(2)
if not data:
break
else:
print(f'I got data: {data}!')
buffer = buffer + data
print(f"All the data is: {buffer}")
connection.sendall(buffer)
Inspect the complete socket sequence: receive two-byte chunks until a carriage return and line feed arrive, then send the accumulated buffer. section 3.2.1
