Python Programming/Sockets
From Wikibooks, open books for an open world
![]() |
This page or section is an undeveloped draft or outline. You can help to develop the work, or you can ask for assistance in the project room. |
HTTP Client[edit]
Make a very simple HTTP client
import socket s = socket.socket() s.connect(('localhost', 80)) s.send('GET / HTTP/1.1\nHost:localhost\n\n') s.recv(40000) # receive 40000 bytes
NTP/Sockets[edit]
Connecting to and reading an NTP time server, returning the time as follows
ntpps picoseconds portion of time ntps seconds portion of time ntpms milliseconds portion of time ntpt 64-bit ntp time, seconds in upper 32-bits, picoseconds in lower 32-bits