The example in this paper describes how Python simply implements TCP packets to send hexadecimal data. Share to everyone for your reference, as follows:
For example: 0x12, 0x34 can be directly spelled as "\x12\x34".
Sample client code:
#-*-encoding:utf-8-*-import jsonimport socketimport sysimport binasciireload (SYS) sys.setdefaultencoding (' Utf-8 ') if __name__== "__main__": s = Socket.socket (socket.af_inet,socket. SOCK_STREAM) S.connect (("Your_host_name", Your_port) s.send ("\xab\xcd\x34\x12\x1f\x00_some_orther_data ") # preceded by hexadecimal data, followed by strings and other body print s.recv (1024x768) s.close ()
More readers interested in Python related content can view this site topic: "Python function Tips Summary", "Python string manipulation Tips", "Python Introductory and Advanced Classic tutorial" and "Python file and directory Operations Tips Summary"
I hope this article is helpful for Python program design.