generated from PlexSheep/rs-base
feat: solutions add solutions for c1-3
cargo devel CI / cargo CI (push) Successful in 1m31s
Details
cargo devel CI / cargo CI (push) Successful in 1m31s
Details
This commit is contained in:
parent
e5befcc9bf
commit
839206c12a
|
@ -0,0 +1,30 @@
|
|||
from io import TextIOWrapper
|
||||
import socket
|
||||
|
||||
REMOTE = "127.0.0.1"
|
||||
PORT = 1337
|
||||
|
||||
def main() -> int:
|
||||
s = socket.socket()
|
||||
s.connect((REMOTE, PORT))
|
||||
sf: TextIOWrapper = s.makefile('rw')
|
||||
|
||||
_response: str = recv(sf)
|
||||
|
||||
sf.close()
|
||||
return 0
|
||||
|
||||
def send(sf: TextIOWrapper, msg: str) -> int:
|
||||
print(f"> {msg}")
|
||||
sent: int = sf.write(f"{msg}\n")
|
||||
sf.flush()
|
||||
return sent
|
||||
|
||||
def recv(sf: TextIOWrapper) -> str:
|
||||
response = sf.readline().strip()
|
||||
print(f"< {response}")
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
|
@ -0,0 +1,32 @@
|
|||
from io import BufferedRWPair
|
||||
import socket
|
||||
|
||||
REMOTE = "127.0.0.1"
|
||||
PORT = 1337
|
||||
|
||||
def main() -> int:
|
||||
s = socket.socket()
|
||||
s.connect((REMOTE, PORT))
|
||||
sf: BufferedRWPair = s.makefile('rwb')
|
||||
|
||||
pl = int.to_bytes(1337, 2, "big")
|
||||
|
||||
_ = send(sf, pl)
|
||||
|
||||
sf.close()
|
||||
return 0
|
||||
|
||||
def send(sf: BufferedRWPair, msg: bytes) -> int:
|
||||
print(f"> {msg.hex()}")
|
||||
sent: int = sf.write(msg + b"\n")
|
||||
sf.flush()
|
||||
return sent
|
||||
|
||||
def recv(sf: BufferedRWPair) -> bytes:
|
||||
response = sf.readline().strip()
|
||||
print(f"< {response}")
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
|
@ -60,7 +60,7 @@ def main() -> int:
|
|||
s.close()
|
||||
return 1
|
||||
|
||||
s.close()
|
||||
sf.close()
|
||||
return 0
|
||||
|
||||
def send(sf: TextIOWrapper, msg: str) -> int:
|
||||
|
|
Loading…
Reference in New Issue