程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python TCP sends hexadecimal characters

編輯:Python
import socket # Import socket modular 
import struct
s = socket.socket() # Create socket 
host = '169.254.68.37' # host IP
port = 2112
s.connect((host,port)) # Active initialization TCP Server connection 
# send_data = input(' Please input the data to be sent ') # Prompt the user to enter data 
a = [0x02 , 0x73 , 0x45 , 0x4E , 0x20 , 0x4C , 0x4D , 0x44 , 0x73 , 0x63 ,
0x61 , 0x6E , 0x64 , 0x61 , 0x74 , 0x61 , 0x20 , 0x31 , 0x03] # Your hex command array 
data = struct.pack("%dB" % (len(a)), *a) # adopt struct Convert to sent hexadecimal string 
s.send(data) # send out TCP data 
print(" Sent ready to receive ")
# Accept the data sent by the other party , The greatest acceptance 1024 byte 
recvData = s.recv(1024).decode()
print(' The received data is :', recvData)
# Close socket 
s.close()

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved