This article describes the Python network programming to read the site root directory method, share for everyone to reference.
The implementation methods are as follows:
Import socket, sys
port = "
quux.org"
filename = "//"
s = socket.socket (socket.af_inet, socket. SOCK_STREAM)
S.connect ((host, Port)
s.sendall (filename+ "\ r \ n") while
(1):
buf = S.RECV (2048)
If not buf:
break
sys.stdout.write (BUF)
The instance of this article runs in Python2.7.6 environment
This instance returns a list of quux.org's root directories
The returned results are as follows:
Iwelcome to Gopher at quux.org! Fake (null) 0 I fake (null) 0 ithis server has a lot of information of historic interest, fake (null) 0 ifunny, or just pl Ain entertaining-all presented in Gopher. Fake (NULL) 0 IThere are many mirrors here is rare or valuable files with the fake (null) 0 Iaim to preserve them in case Their host disappears. Please READ fake (NULL) 0 i ' about this Server ' for IMPORTANT NOTES and LEGAL information. Fake (null) 0 I fake (null) 0 0About This server/about this Server.txt gopher.quux.org + 1archives/archives Gopher.qu ux.org + 1books/books gopher.quux.org + 1communication/communication gopher.quux.org-ithis directory contains The entire text of the book fake (null) 0 i "We the media:grassroots journalism by the people, for the people" fake (null ) 0 Iby Dan Gillmor in various formats. Fake (null) 0 I fake (null) 0 Ifeel free to download and enjoy. Fake (NULL) 0 1computers/computers gopher.quux.org + 1Current Issues and Events (Updated ApR. 2002)/current gopher.quux.org + 1Development projects/devel gopher.quux.org-0Gopher ' s 10th ANNIVERSARY/3 0.0.txt gopher.quux.org 1Government, Politics, conflict/government gopher.quux.org + 0How to Help/how to Help.txt gopher.quux.org + 1Humor and Fun/humor and Fun gopher.quux.org + 1Index to Quux.org/archives/index Gophe r.quux.org 1internet/internet gopher.quux.org + 1Other Gopher servers/software/gopher/servers gopher.quux.org 70 1 People/people gopher.quux.org + 1reference/reference gopher.quux.org + 1Software and Downloads/software Gopher.qu
ux.org + 1The Gopher project/software/gopher gopher.quux.org 0What ' s new/whatsnew.txt gopher.quux.org 70 +
Hopefully this article will help you with your Python programming