套接字概念_操作系统概念—套接字

套接字概念

Sockets are strategies that are used for communication between processes. It is mainly used in client-server based systems. When two systems want to communicate with each other, sockets are the endpoint on either end of the communicating processes.

套接字是用于进程之间通信的策略。 它主要用于基于客户端-服务器的系统。 当两个系统要相互通信时,套接字是通信过程两端的端点。

  • A pair of processes communicating over a network employs a pair of sockets-one for each process.

    通过网络通信的一对进程使用一对套接字,每个进程一个。

When two processes want to communicate, there needs to be a connection between them and at each end of the connection each of this processes will employ a socket each, so a pair of communicating processes over a network will employ a pair of sockets one for each process.

当两个进程要进行通信时,它们之间需要有一个连接,并且在该连接的每一端,每个进程将各自使用一个套接字,因此,网络上的一对通信进程将分别使用一对套接字。处理。

How can we Identify a Socket?

我们如何识别套接字?

  • A socket is identified by an IP address concatenated with a port number.

    套接字由与端口号连接的IP地址标识。

    Servers implementing specific services (such as TELNET, FTP, and HTTP) listen to well-known ports.

    实现特定服务(例如TELNET,FTP和HTTP)的服务器侦听众所周知的端口。

    For example,

    例如,

  • TELNET server is used for remote logging which listens to port 23

    TELNET服务器用于侦听端口23的远程日志记录
  • FTP (File transfer protocol) is used for transferring files server listens to port 21

    FTP(文件传输协议)用于传输文件,服务器侦听端口21
  • Web or Http (Hypertext transfer protocol) server listens to port 80

    Web或Http(超文本传输​​协议)服务器侦听端口80
  • A port number is going to identify each of the processes, services that are going to be provided.

    端口号将标识将要提供的每个进程和服务。

All ports below 1024 are considered well known; we can use them to implement standard services.

所有低于1024的端口都被认为是众所周知的; 我们可以使用它们来实现标准服务。

How does communication between these processes employing a pair of sockets take place?

使用一对套接字的这些进程之间如何通信?

  • The server waits for incoming client requests by listening to a specified port. Once a request is received, the server accepts a connection from the client socket to complete the connection.

    服务器通过侦听指定的端口来等待传入的客户端请求。 收到请求后,服务器将接受来自客户端套接字的连接以完成连接。

In a Client-Server systems, the Client asks for information from the server and the Server provides the information to the client. In order for the client to communicate to the server and the server to communicate back to the Client, there needs to be a connection between the Client and the Server. In order to establish this connection, we are going to use sockets.

在客户端服务器系统中,客户端从服务器请求信息,服务器将信息提供给客户端。 为了使客户端能够与服务器通信,并且服务器能够与客户端通信,客户端与服务器之间需要建立连接。 为了建立此连接,我们将使用套接字。

Image for post
Communication using Sockets 使用套接字通讯

From the diagram above, The first part is the Host and the second part is the Web server. The first part is the Client, the second part is the Server.

在上图中,第一部分是主机,第二部分是Web服务器。 第一部分是客户端,第二部分是服务器。

  • The Client wants to request something from the server, the Server has to fulfill the request by given whatever the Client asks from the Server. In other, for this to occur, there must be a communication link between the Server and the Client. The communication link is being established using the concept of Socket which we defined earlier.

    客户端要向服务器请求某些内容,服务器必须通过给出客户端向服务器提出的任何要求来满足请求。 换句话说,要使这种情况发生,服务器与客户端之间必须存在通信链接。 使用我们前面定义的Socket概念来建立通信链接。
  • From the first part of the diagram, a Client process is trying to establish a connection between the Client and the Server. The host computer will assign a port number to this process which wants to communicate with the server.

    从图的第一部分开始,一个客户端进程正在尝试在客户端和服务器之间建立连接。 主机将为该进程分配一个端口号,该进程希望与服务器进行通信。
  • The IP address of the Host Computer from the diagram above is 146.86.5.20 a process that belongs to the Host computer wants to communicate with the Web Server. For that to be possible, a specific port number will be assigned by the Host computer to the Client process.

    上图中的主机计算机的IP地址为146.86.5.20 ,属于主机计算机的进程希望与Web服务器通信。 为此,主机会将特定的端口号分配给客户端进程。

    The IP address is then assigned a port number

    然后为IP地址分配一个端口号

    146.86.5.20:1625:1625 A port number is an arbitrary number greater than 1024. It is greater than 1024 because the port numbers below 1024 are considered well known and are used for implementing standard services.

    146.86.5.20:1625:1625端口号是大于1024的任意数字。它大于1024,因为低于1024的端口号被认为是众所周知的,并用于实现标准服务。

  • Similarly in part B (The webserver) the Web server has a socket. the socket belongs to the process in the Web server that is going to communicate with the Client process. It has an IP address and port number 161.25.19.8:80

    类似地,在B部分(Web服务器)中,Web服务器具有一个套接字。 套接字属于将与客户端进程进行通信的Web服务器中的进程。 它具有IP地址和端口号161.25.19.8:80

Port number 80 is less than 1024 because it’s the Web server and not the Client. The Client is trying to access some services from the Server, Port number 80 belongs to a standard service.

端口号80小于1024,因为它是Web服务器,而不是客户端。 客户端正在尝试从服务器访问某些服务,端口号80属于标准服务。

The packets that are traveling from the Client process to the Server process are delivered appropriately based on the port numbers

从客户端进程到服务器进程的数据包将根据端口号正确传递

If another process from the Host computer wants to communicate to the same socket of the Web server, that process will again be assigned another socket. The socket number will be a new number different from 1625 and greater than 1024

如果来自主机的另一个进程希望与Web服务器的同一套接字通信,则将再次为该进程分配另一个套接字。 套接字号将是一个不同于1625且大于1024的新数字

Conclusion

结论

This is how communication between systems/processes takes place using Sockets. This is another strategy that is used for communication between processes and this is very specifically used for the Client-Server system.

这就是使用套接字在系统/进程之间进行通信的方式。 这是用于进程之间通信的另一种策略,非常专门用于客户端-服务器系统。

The Sockets are specifically used only for the Client-Server based systems.

套接字仅专门用于基于客户端服务器的系统。

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

如果此帖子有帮助,请单击下面的拍手👏按钮几次,以表示对作者的支持!

翻译自: https://medium.com/@thecraftman/operating-system-concepts-sockets-a78ddb9b5f9c

套接字概念

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值