Skip to content

Instantly share code, notes, and snippets.

@okurka12
Created April 13, 2025 13:49
Show Gist options
  • Save okurka12/87460576c644f33f38551cb819cdc075 to your computer and use it in GitHub Desktop.
Save okurka12/87460576c644f33f38551cb819cdc075 to your computer and use it in GitHub Desktop.
test for IPK25chat client TCP stream
#
# IPK25chat client TCP stream test
# author: vita v22.0
# date: 13. 4. 2025
# python 3.13.0
#
import socket
ADDRESS = "127.0.0.1"
PORT = 4567
def test(s: str) -> None:
escaped = s.replace("\n", "\\n").replace("\r", "\\r")
print(f"Press enter to send \"{escaped}\": ", flush=True, end="")
input()
csock.send(s.encode("ascii"))
print("sent")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((ADDRESS, PORT))
sock.listen()
print("socket is bound and listening")
csock, _ = sock.accept()
print("connected")
test("reply ok is ok\r\n")
test("msg from 2 is 2\r\nmsg from 3 is 3\r\nmsg from 4 is 4\r\n")
test("msg from 5 is 5\r\nmsg from 6 is 6\r\nmsg from 7 is")
test(" 7\r\n")
test("msg from")
test(" 8 is 8\r\n")
test("bye from xd\r\n")
print("Pres enter to shutdown the socket: ", flush=True, end="")
input()
csock.shutdown(socket.SHUT_RDWR)
csock.close()
sock.shutdown(socket.SHUT_RDWR)
sock.close()
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment