0
点赞
收藏
分享

微信扫一扫

windows环境批量删除指定目录下的全部指定文件

新鲜小饼干 2024-10-12 阅读 14
网络


import socket
import time

HOST = ''  # Symbolic name meaning all available interfaces
PORT = 7778  # Port number (non-privileged ports are > 1023),Same port as used by the server
COUNT_LIMIT = 60  # Limit of data packets to send

count = 0  # Initialize counter

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 count < COUNT_LIMIT:  # Loop until we reach the limit
            time.sleep(0.1)  # Sleep for 0.1 seconds
            conn.sendall(b'1')  # Send the number '1'
            count += 1  # Increment counter after each send
        else:
            print(f'Sent {count} packets, closing connection.')  # Print message when limit is reached
 

举报

相关推荐

0 条评论