Skip to content

Instantly share code, notes, and snippets.

@RoyBellingan
Created January 22, 2022 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoyBellingan/b387065f58196b0eb10d16c206c65207 to your computer and use it in GitHub Desktop.
Save RoyBellingan/b387065f58196b0eb10d16c206c65207 to your computer and use it in GitHub Desktop.
mt.py
#!/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