def server(): io = SansIORW(encoding="utf-8") version, command, port, ipv4 = yield from io.read_struct("BBH4s") assert version == 4 assert command == 1 assert port == 123 assert ipv4 == b"\x7f\x00\x00\x01" user_id = yield from io.read_c_string() assert user_id == "yoba" yield from io.connect(ipv4, port) yield from io.write_struct("BBH4s", 0, 0x5a, 0, b"\x7f\x00\x00\x01") yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("BBH4s", 4, 1, 123, b"\x7f\x00\x00\x01") yield from io.write_c_string("yoba") prefix, code, port, ipv4 = yield from io.read_struct("BBH4s") assert prefix == 0 assert code == 0x5a assert port == 0 assert ipv4 == b"\x00" * 4 yield from io.passthrough()
def __init__(self): self.buffer = [] self.io = SansIORW(encoding="utf-8")
def server(): io = SansIORW(encoding="utf-8") yield from io.read_exactly(1)
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("B", 5) yield from io.write_struct("BB", 1, 0) version, auth_method = yield from io.read_struct("BB") assert (version, auth_method) == (5, 0) yield from io.write_struct("4B", 5, 1, 0, 3) yield from io.write_pascal_string("python.org") yield from io.write_struct("H", 666) version, command, zero, address_type = yield from io.read_struct("4B") assert (version, command, zero, address_type) == (5, 0, 0, 1) ipv4, port = yield from io.read_struct("4sH") assert (ipv4, port) == (b"\x00" * 4, 0) yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("B", 5) yield from io.write_struct("B", 0) yield from io.passthrough()
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 client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("BBH4s", 4, 2, 123, b"\x7f\x00\x00\x01") yield from io.write_c_string("yoba") yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write(b"\x06") yield from io.passthrough()