Python 简明教程

Python - Network Programming

Python 标准库中的线程模块能够处理多线程及其在单进程中的交互。在同一台计算机上运行的两个进程之间的通信由 Unix 域套接字处理,而对于在不同计算机上运行并连接到 TCP(传输控制协议)的进程,则使用 Internet 域套接字。

The threading module in Python’s standard library is capable of handling multiple threads and their interaction within a single process. Communication between two processes running on the same machine is handled by Unix domain sockets, whereas for the processes running on different machines connected with TCP (Transmission control protocol), Internet domain sockets are used.

network programming

Python 标准库包含各种内置模块,它们支持进程间通信和网络连接。Python 提供了两个级别的网络服务访问。在较低级别,你可以访问底层操作系统中的基本套接字支持,这使你能够为面向连接和无连接协议实现客户端和服务器。

Python’s standard library consists of various built-in modules that support interprocess communication and networking. Python provides two levels of access to the network services. At a low level, you can access the basic socket support in the underlying operating system, which allows you to implement clients and servers for both connection-oriented and connectionless protocols.

Python 还具有库,提供对特定应用程序级网络协议的更高级访问,例如 FTP、HTTP 等。

Python also has libraries that provide higher-level access to specific application-level network protocols, such as FTP, HTTP, and so on.

Protocol

Common function

Port No

Python module

HTTP

Web pages

80

httplib, urllib, xmlrpclib

NNTP

Usenet news

119

nntplib

FTP

File transfers

20

ftplib, urllib

SMTP

Sending email

25

smtplib

POP3

Fetching email

110

poplib

IMAP4

Fetching email

143

imaplib

Telnet

Command lines

23

telnetlib

Gopher

Document transfers

70

gopherlib, urllib