udp客户端与服务器端模型_客户端-服务器模型

udp客户端与服务器端模型

As mentioned in the previous article, one of the requirements of using on a page is that it must be on a server in order to work. This often confuses web developers who are only familiar with and : until this point, they have been able to store and view their web pages on almost any digital device. That is not true of pages that feature PHP.

如上一篇文章中所述,在页面上使用的要求之一是它必须在服务器上才能正常工作。 这通常会使仅熟悉 Web开发人员感到困惑:到目前为止,他们已经能够在几乎任何数字设备上存储和查看其网页。 对于具有PHP的页面,情况并非如此。

In order to understand why, we need to look at the very basics of the internet. In particular, we must define two terms:

为了理解为什么,我们需要看一下互联网的基础知识。 特别是,我们必须定义两个术语:

A client is, for our purposes, a device, or some software, that requests a resource on the internet. The client is often, but not exclusively, a web browser running on a computer. Other possible clients include internet-accessing software running on other devices such as smartphones, eMail programs, games, etc.

出于我们的目的, 客户端是在Internet上请求资源的设备或某些软件。 客户端通常是(但不限于)计算机上运行的Web浏览器。 其他可能的客户端包括在其他设备(例如智能手机,电子邮件程序,游戏等)上运行的互联网访问软件。

A server is software or a device that provides services in response to requests from clients. The possible services are many and varied:

服务器是响应客户请求提供服务的软件或设备。 可能的服务多种多样:

  • Print servers forward documents from clients on a network to appropriate printers, controlling printer queues and priorities.

    打印服务器将文档从网络上的客户端转发到适当的打印机,从而控制打印机队列和优先级。

  • Game servers provide a single location for game clients to form teams, and communicate the moves, current positions, actions, and scores of players.

    游戏服务器为游戏客户提供一个单一位置来组建团队,并交流玩家的移动,当前位置,动作和得分。

  • File servers store files in a centralized location so that everyone in an organization has equal access to resources.

    文件服务器将文件存储在集中位置,以便组织中的每个人都可以平等地访问资源。

  • Web servers store web pages and associated files (such as images), and provide those resources in response to client requests.

    Web服务器存储网页和关联的文件(例如图像),并响应客户端请求提供这些资源。

Servers are often specialized machines. If they consider them at all, most people probably think of servers as giant humming computers with blinking lights in a vast, cavern-like room. The reality is that almost any device with a processor can be turned into a server: what makes them special is the software, not the nature of the physical hardware that the server runs on. Obviously, computers with more memory, hard drive space, and processors tend to make better servers, as most are expected to respond to simultaneous requests from dozens to thousands of clients.

服务器通常是专用计算机。 如果他们完全考虑它们,大多数人可能会将服务器视为巨大的嗡嗡声计算机,在一个巨大的类似洞穴的房间中闪烁的灯光。 实际上,几乎任何带有处理器的设备都可以变成服务器:使它们与众不同的是软件 ,而不是服务器运行的物理硬件的性质。 显然,具有更多内存,硬盘空间和处理器的计算机往往会制造出更好的服务器,因为大多数服务器有望响应数十个到数千个客户端的同时请求。

So in the traditional client-server model, a request for a web page could be shown as something like what you see at the top of this article.

因此,在传统的客户端-服务器模型中,对网页的请求可能显示为类似于您在本文顶部看到的内容。

Note that the only role for the server during this simple request is to provide the requested files: the HTML page, CSS, JavaScript code, and images. It does not process any of this material: it just finds it and hands it over. All the processing, or interpretation, is done by the client. That is, the web server does not “understand” HTML, CSS, or JavaScript: to the server, they are all just text files. It is your client that interprets the code in these files and displays the result.

请注意,在此简单请求期间,服务器的唯一作用是提供所请求的文件:HTML页面,CSS, JavaScript代码和images 。 它不处理任何材料:它只是找到并交给了它。 所有处理或解释都是由客户端完成的。 也就是说,Web服务器不能“理解” HTML,CSS或JavaScript:对于服务器来说,它们全都是文本文件。 是您的客户端解释这些文件中的代码并显示结果。

A good analogy for the client-server relationship is that of a well-to-do Victorian household in the late 19th century. You, a London gentleman or woman, reside in the upper story of your home. The “help” – the servants and cooks – live downstairs. Being a very proper class-conscious Victorian, you don’t ever wish to be seen by the staff. Instead, all interaction with the help downstairs is made via a dumbwaiter: a small goods elevator in the wall that travels up and down between the floors. When you are hungry, you write requests for food on little slips of paper, sending them down in the dumbwaiter. The hired help reads the note, places food in the dumbwaiter, and sends it back upstairs to fulfill your request.

一个很好的比喻,对客户端服务器的关系是一个富裕的维多利亚做家庭在19 世纪后期。 您,伦敦的绅士或女人,居住在您房屋的顶层。 仆人和厨师的“帮助”住在楼下。 作为一个非常适合上课的维多利亚时代人,您永远都不想被员工看到。 取而代之的是,所有与楼下帮助人员的互动都是通过一个哑巴服务员完成的:墙上的一台小型电梯,在楼层之间上下移动。 肚子饿的时候,您可以在纸条上写下对食物的要求,然后将其发送到笨拙的服务员中。 聘请的帮助人员会读取便签,将食物放在哑吧侍者中,然后将其寄回楼上,以完成您的要求。

At the beginning of this arrangement, you have very primitive level of communication with your staff. If you ask for potatoes, the servants will simply put potatoes in the dumbwaiter and send them up to you – it’s up to you to do the peeling, mashing, and cooking. This means that your staff can respond very quickly to requests, but it places a good portion of the work of actually making food on you.

在开始这种安排时,您与员工之间的沟通水平非常原始。 如果您要土豆,仆人会简单地将土豆放在饺子里,然后将土豆送到您的手中,这取决于您去皮,捣碎和烹饪。 这意味着您的员工可以非常Swift地响应请求,但这实际上为您制作了食物。

In the same way, all HTML, CSS and (in most cases) JavaScript code is requested from the server but is interpreted (i.e. run or executed) by the client. Historically, this is one of the reasons that Flash (another format that is primarily client-side) is not supported or blocked on modern mobile phones: the computing power needed to run complex Flash was beyond the capacity of the processors in the first smartphones.

同样,所有HTMLCSS和(大多数情况下) JavaScript代码都是从服务器请求的 ,但是由客户端解释 (即运行或执行)。 从历史上看,这是现代手机不支持或阻止Flash(另一种主要是客户端格式)的原因之一:运行复杂Flash所需的计算能力超出了第一批智能手机中处理器的能力。

As a basic request-response system, this works well. If you want more work done by your help staff (you send a request down for potatoes, and your cooks prepare potatoes au gratin in just the way you like) then the server must do more work. This means you (the client) gain prepared meals, but at the expense of working your servants harder. Obviously, if you have a dinner party, during which all of your guests order special meals, then your serving staff will have to work even harder. Too many requests and deliveries flying up and down the dumbwaiter run the risk of slowing down service.

作为基本的请求-响应系统,这很好。 如果您希望帮助人员做更多的工作(向土豆发送请求,而您的厨师以自己喜欢的方式准备土豆 ),那么服务器必须做更多的工作。 这意味着您(客户)可以准备饭菜,但要以牺牲您的仆人的辛苦为代价。 显然,如果您有一个晚宴聚会,在此期间您所有的客人都点了特别的饭菜,那么您的服务人员将不得不更加努力地工作。 笨拙的服务员上下飞行的请求和交付太多,有降低服务速度的风险。

In our case, why would you want to place more work on the server? Typically, server-side languages are used to create dynamic web pages: features on the page that alter under certain conditions. HTML (and to a certain degree, CSS) are stateless: they have no comprehension of the passing of time or (broadly speaking) the actions of a user on a web page. Some scenarios for using a server-side language such as PHP might include:

就我们而言,为什么要在服务器上进行更多工作? 通常,服务器端语言用于创建动态网页:页面上的功能在某些情况下会发生变化。 HTML (一定程度上是CSS )是无状态的:它们不了解时间的流逝或用户在网页上的行为(广义上来说)。 使用服务器端语言(例如PHP)的一些方案可能包括:

Combing both server-side and client-side processing, our diagram becomes:

Client request, server response, with both client-side and server-side processing

结合服务器端和客户端处理,我们的图变为:

Central to this model is the issue of balancing client-side processing with server-side demands. You will never be able to fully anticipate the power or abilities of web clients (they will always have different connection speeds, different browser versions and plugins, different processor speeds, etc). But placing too much work on servers starts to bog them down. Ideally, the two are balanced: some work is done by the client (interpreting HTML, CSS, JavaScript and images), and some by the server (PHP, ASP, and other server-side technologies), to create a seamless experience.

该模型的核心是平衡客户端处理与服务器端需求之间的问题。 您将永远无法完全预期Web客户端的功能或能力(它们将始终具有不同的连接速度,不同的浏览器版本和插件,不同的处理器速度等)。 但是,在服务器上放置过多的工作会开始陷入困境。 理想情况下,两者是平衡的:某些工作由客户端(解释HTMLCSSJavaScript图像 )完成,而某些工作由服务器(PHP,ASP和其他服务器端技术)完成,以创造无缝的体验。

There are some other important reasons to use server-side technologies:

使用服务器端技术还有其他一些重要原因:

Reliability 可靠性
always work. You don’t have to worry about browser type, available plugins, or platform: the server always remains the same, and PHP code always works. 始终有效。 您不必担心浏览器的类型,可用的插件或平台:服务器始终保持不变,PHP代码始终有效。
Security 安全
Server-side code is inherently more secure than client-side, as the client never sees the server code, just as our Victorian gentleman never saw his servants: the server works to fulfill a client request, and sends the completed order. The client never sees the actual process of chopping, cooking, etc.
服务器端代码从本质上比客户端端更安全,因为客户端从未看到过服务器代码,就像维多利亚时代的绅士从未看到过他的仆人一样:服务器工作来满足客户端请求,并发送完成的订单。 客户从未见过切碎,烹饪等的实际过程。

翻译自: https://thenewcode.com/137/The-Client-Server-Model

udp客户端与服务器端模型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值