Liu/post.py

18 lines
460 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import socket
# 创建一个socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 建立连接:
s.connect(('localhost', 9996))
while True:
try:
# 输入需要发送的数据
data = input("Enter the voltage data you want to send (or 'exit' to quit): ")
if data.lower() == 'exit':
break
# 发送数据:
s.send(data.encode())
except KeyboardInterrupt:
break
# 关闭连接
s.close()