The purpose of blogging is to simply keep track of the problems that you have encountered while learning the Python web programming book, as well as the changes that the book code cannot run in python3.5.
I hope other friends who study this book will be able to save valuable time through my blog. Because just started to learn python, and the network is not very understanding of things, there are many things without explanation, will be supplemented.
TIME1970 = 2208988800l# is January 1, 1900 00:00:00~1970 year January 1 00:00:00 total number of seconds
Syntaxerror:invalid syntax
In Python 3, there is only one integer type int, expressed as a long integer, without a long in python2.
Def sntp_client ():
client = Socket.socket (socket.af_inet, socket. SOCK_DGRAM)
# Client main construction of the first three fields can be, after all the bits are filled 0
# ' \x1b ' expanded to 00 100 011 respectively filled Li, VN, mode field
# The remaining 47 * 8 = 376 bits are filled with 0
D ATA = ' \x1b ' + * '
#转化为字节形式
client.sendto (Data.encode (), (Ntp_server, 123))
data, address = Client.recv From (1024)
if data:
print (' Response received from: ', address)
#按照给定的格式 (FMT) resolves a byte stream string that returns the parsed tuple
t = struct.unpack ('!12i ', data) [ten]
t-= TIME1970
#ctime Converts the date and time to the string
print (' \ttime=%s '% Time.ctime (t))