def server(): io = SansIORW(encoding="utf-8") version, one, auth_method = yield from io.read_struct("BBB") assert (version, one, auth_method) == (5, 1, 0) yield from io.write_struct("BB", 5, 0) version, command, zero, address_type = yield from io.read_struct("4B") assert (version, command, zero, address_type) == (5, 1, 0, 3) domain = yield from io.read_pascal_string() port = yield from io.read_struct("H") assert (domain, port) == ("python.org", 666) yield from io.write_struct("4B", 5, 0, 0, 1) yield from io.write(b"\x00" * 4) yield from io.write_struct("H", 0) yield from io.passthrough()
def server(): io = SansIORW(encoding="utf-8") version, one, auth_method = yield from io.read_struct("BBB") assert version == 5 assert one == 1 assert auth_method == 2 yield from io.write_struct("BB", 5, 2) auth_version = yield from io.read_struct("B") assert auth_version == 1 username = yield from io.read_pascal_string() password = yield from io.read_pascal_string() assert username == "yoba" assert password == "foo" yield from io.write_struct("BB", 1, 1) yield from io.passthrough()