python
import socket
import struct
import time
def getBytesPack(array_data):
bytes_data = bytes()
for i in range(len(array_data)):
bytes_data += struct.pack('B', array_data[i])
return bytes_data
if __name__ == '__main__':
IP = "192.168.1.223"
PORT = 60000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
s.connect((IP, PORT))
send_data = [0xaa, 0xdd, 0xcc, 0xbb, 221, 226]
send_pack = getBytesPack(send_data)
for i in range(10):
s.send(send_pack)
time.sleep(1)
测试效果: