port and socket 2022-11-08

2022-11-07  本文已影响0人  9_SooHyun

port

Virtual ports are part of TCP/IP networking(port是tcp/ip协议层面的概念).

A port is a virtual point where network connections start and end. Each port is associated with a specific process or service.

These ports allow software applications to share hardware resources without interfering with each other. Operating system automatically manage network traffic traveling via their virtual ports: emails go to a different port than webpages, for instance, even though both reach a computer over the same Internet connection. Network firewalls additionally provide some control over the flow of traffic on each virtual port for security purposes.

socket

The combination of an IP address and a port is strictly known as an endpoint and is called a socket. This usage originates with RFC793, the original TCP specification.
see https://www.rfc-editor.org/rfc/rfc793

A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections. For data exchange, a connection is needed, and in a connection a pair of sockets come into play.

In most C-derived languages, TCP connections are established and manipulated using methods on an instance of a Socket class. Although it is common to operate on a higher level of abstraction, typically an instance of a NetworkStream class, this generally exposes a reference to a socket object. To the coder this socket object appears to represent the connection because the connection is created and manipulated using methods of the socket object.

c家族的编程语言大都直接通过 Socket class 的实例方法进行网络编程,而其他编程语言大都在更高层次进行网络服务的开发,c果然更底层。。

在编程语言中,也许多个Socket instance绑定了相同的IP和port,这表示它们描述了同一个socket,但这些instance在编程语言层面属于不同的实例
do not confuse the socket objects(created using Java,C# etc) with the socket primitive provided by the operating system. At higher level of abstraction you may have many objects with same IP and port but at the OS level they map to the same socket. Thus you can identify a socket(OS primitive and not some object in xyz language) with IP and Port.

上一篇下一篇

猜你喜欢

热点阅读