Created
January 22, 2022 14:35
-
-
Save RoyBellingan/b387065f58196b0eb10d16c206c65207 to your computer and use it in GitHub Desktop.
mt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import logging | |
import threading | |
import time | |
import socket | |
HOST = '127.0.0.1' # Standard loopback interface address (localhost) | |
PORT = 65432 # Port to listen on (non-privileged ports are > 1023) | |
def thread_function(name): | |
while True: | |
print("miao") | |
time.sleep(1) | |
x = threading.Thread(target=thread_function, args=(1,)) | |
x.start() | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.bind((HOST, PORT)) | |
s.listen() | |
conn, addr = s.accept() | |
with conn: | |
print('Connected by', addr) | |
while True: | |
data = conn.recv(1024) | |
if not data: | |
break | |
conn.sendall(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment