socket是什么?(翻译)

时间:2023-03-10 07:01:41
socket是什么?(翻译)

根据*的答案:

原文:A socket represents a single connection between two network applications. These two applications nominally run on different computers, but sockets can also be used for interprocess communication on a single computer. Applications can create multiple sockets for communicating with each other. Sockets are bidirectional, meaning that either side of the connection is capable of both sending and receiving data. Therefore a socket can be created theoretically at any level of the OSI model from 2 upwards. Programmers often use sockets in network programming, albeit indirectly. Programming libraries like Winsock hide many of the low-level details of socket programming. Sockets have been in widespread use since the early 1980s. A port represents an endpoint or "channel" for network communications. Port numbers allow different applications on the same computer to utilize network resources without interfering with each other. Port numbers most commonly appear in network programming, particularly socket programming. Sometimes, though, port numbers are made visible to the casual user. For example, some Web sites a person visits on the Internet use a URL like the following:

http://www.mairie-metz.fr:8080/ In this example, the number 8080 refers to the port number used by the Web browser to connect to the Web server. Normally, a Web site uses port number 80 and this number need not be included with the URL (although it can be).

翻译:socket代表两个网络应用之间的单个连接。这两个应用通常运行在不同的电脑上,但socket也可以被用作一台电脑间不同进程间的通信。socket是双向的,这意味着连接的两边都可以发送和接受数据。这样,一个socket理论上可以在OSI模型的第二层以上的任意层建立。程序员常在网络编程中使用socket,尽管不是直接地使用。像Winsock这样的程序库隐藏了socket编程的许多底层细节。socket自从1980年代以来已经被广泛地使用。端口(port)代表端点(endpoint),通道(channel)代表网络通信。端口号允许一台电脑上的不同应用在不干涉彼此的前提下使用网络资源。端口号在网络中经常出现,特别是socket编程。虽然有时端口号对于临时用户是明显的。例如,用url访问如下网站时:

http://www.mairie-metz.fr:8080/

在这个例子中,数字8080表示被Web浏览器连接到Web服务器的端口号。一般来说,网站使用80端口,并且这个数字不需要被包括在url中(虽然也可以被包括)。