2024-02-04 21:36:00 +08:00
|
|
|
|
import socket
|
2024-02-20 09:20:41 +08:00
|
|
|
|
import random
|
|
|
|
|
import time
|
2024-02-04 21:36:00 +08:00
|
|
|
|
|
|
|
|
|
# 创建一个socket:
|
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
# 建立连接:
|
|
|
|
|
s.connect(('localhost', 9996))
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
# 输入需要发送的数据
|
2024-02-20 09:20:41 +08:00
|
|
|
|
data = str(random.randint(1, 10))
|
|
|
|
|
time.sleep(0.1)
|
2024-02-04 21:36:00 +08:00
|
|
|
|
if data.lower() == 'exit':
|
|
|
|
|
break
|
|
|
|
|
# 发送数据:
|
|
|
|
|
s.send(data.encode())
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
break
|
|
|
|
|
# 关闭连接
|
|
|
|
|
s.close()
|