python network

文章讲述了在TCP传输中为何需要对字符串进行编码,因为send()方法不能发送字符串,必须转换为字节流。还讨论了send()和sendall()的区别,sendall()确保所有数据都被发送。此外,提到了最大传输单元(MTU)对发送数据量的限制。同时,文章也涉及了Python中使用threading模块创建线程,包括Timer的用法以及JSON的序列化与反序列化操作。
摘要由CSDN通过智能技术生成

call the sync function after 2 seconds 

        t = threading.Timer(2, self.sync)
        t.start()

 为什么TCP传输需要编码

send() can not send a string (会报错), so must use encode() before send()

TCP使用字节流传输 -> 也就是in bytes format

send和sendall的区别

the maximum number of bytes that can be sent using the send() method depends on the maximum transmission unit (MTU) of the underlying network. The MTU is the largest size of data that can be transmitted in a single network packet.

sendall()会不断用send()知道把所有的信息发出去

一个send()最多只能发送1024bytes

JSON

# dumps: dict -> JSON string
msg = json.dumps(message_dictionary)
# load: JSON string -> dict
file_directory = json.loads(directory_response_message)

thead的用法

Python 创建线程的两种方式_季布,的博客-CSDN博客_python threatPython 创建协程的方式主要有以下两种Python3中提供了一个内置模块threating.Thred,可以非常方便的创建协程threading.Thread() 一般接收两个参数:线程函数名:线程执行的函数(任务),由我们自已定义,注意不要加();线程函数的参数:线程函数名所需的参数,以元组的形式传入。若不需要参数,可以不指定(如果元组就一个参数要加逗号)。使用Thread类的构造器创建线程# 自定义线程要执行的函数def test(par = 'jibu'): for infohttps://blog.csdn.net/weixin_47906106/article/details/121559692?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167652418316800182794680%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=167652418316800182794680&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-2-121559692-null-null.142^v73^insert_down1,201^v4^add_ask,239^v1^insert_chatgpt&utm_term=python%20threat&spm=1018.2226.3001.4187

解码成bytes

解码意味着string通过一种规定(字符集的编码库)转变那bytes格式

Mastering Python Networking English | 2017 | ISBN-10: 1784397008 | 446 pages | PDF + EPUB + MOBI (conv) | 9.76 Mb Key Features Build the skills to perform all networking tasks using Python with ease Use Python for Network Device Automation, DevOps, and Software Defined Networking Practical guide to networking with Python Book Description You will begin with a review of the TCP/IP Protocol Suite and to refresh the core elements of the Python language. Next you will start using Python to automate network devices and achieve all that you want from your network. You will then move to using Python for DevOps where you will be securing networks, monitoring networks, and building network services. In the last module, you will use Python for SDN, where you will use Python with OpenFlow, OpenStack , OpenDayLight, and NFV. Finally you will use everything you have learned so far in this book to construct a Python-based migration plan to go from legacy to a scalable SDN-based network. By the end of the book you will have all the skills required to perform complex network-related tasks with Python What you will learn Review of all the fundamentals of Python and TCP/IP suite Use Python to execute commands when the device does not support the API or programmatic interaction with the device Implement automation techniques by integrating Python with Cisco, Juniper, and and Arista EAPI Integrate Ansible using Python to control Cisco, Juniper, and Arista networks Achieve Network security with Python Build high-performing web services with Python Construct a Python-based migration plan from legacy to a scalable SDN-based network. Download from icerbox.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值