Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Python Programming/Networks

From Wikibooks, open books for an open world
<Python Programming
Previous: InternetIndexNext: Databases


This page or section is an undeveloped draft or outline.
You can help todevelop the work, or you can ask for assistance in theproject room.

Sockets

[edit |edit source]

Python can also communicate via sockets.

Connecting to a server

[edit |edit source]

This simple Python program will fetch a 4096 byte HTTP response from Google:

importsocket,syssock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.connect(("google.com",80))sock.send('GET / HTTP/1.1\r\n')sock.send('User-agent: Mozilla/5.0 (wikibooks test)\r\n\r\n')print(sock.recv(4096))

High-level interfaces

[edit |edit source]

Most Python developers will prefer to use a high-level interface over using sockets, such asTwisted andurllib2.

Previous: InternetIndexNext: Databases
Retrieved from "https://en.wikibooks.org/w/index.php?title=Python_Programming/Networks&oldid=4070794"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp