Python简单实现TCP包发送十六进制数据的方法

WBOY
Release: 2016-06-10 15:05:10
Original
3323 people have browsed it

本文实例讲述了Python简单实现TCP包发送十六进制数据的方法。分享给大家供大家参考,具体如下:

举例: 0x12, 0x34可以直接拼成 "\x12\x34"。

客户端代码示例:

#-*- encoding: utf-8 -*-
import json
import socket
import sys
import binascii
reload(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") # 前面为十六进制数据,后面可接字符串等正文
    print s.recv(1024)
    s.close()

Copy after login

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!