tcp - client 例程#
本示例程序用于对 CanMV 开发板进行一个 tcp client的功能展示。
#配置 tcp/udp socket调试工具
import socket
import time
PORT=60000
def client():
#获取地址及端口号 对应地址
ai = socket.getaddrinfo("10.100.228.5", PORT)
#ai = socket.getaddrinfo("10.10.1.94", PORT)
print("Address infos:", ai)
addr = ai[0][-1]
print("Connect address:", addr)
#建立socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
#连接地址
s.connect(addr)
for i in range(10):
str="K230 tcp client send test {0} \r\n".format(i)
print(str)
#print(s.send(str))
#发送字符串
print(s.write(str))
time.sleep(0.2)
#time.sleep(1)
#print(s.recv(4096))
#print(s.read())
#延时1秒
time.sleep(1)
#关闭socket
s.close()
print("end")
#main()
client()