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的用法
解码成bytes
解码意味着string通过一种规定(字符集的编码库)转变那bytes格式