# BS 架构与 CS 架构

## 定义

* BS 架构指`Browser-Server`结构，即使用浏览器与服务器之间传输构建应用
* CS 架构指`Client-Server`结构，在客户端和服务器之间传输以构建应用

## 通讯方向

* BS 架构在通信上常使用 ajax，是一问一答，Browser 发出请求，Server 返回响应，一般来说 Server 不会自发发出请求给 Browser
* CS 架构在通信上常使用双向通信，Client 与 Server 建立一个 socket，能够双向发出请求和响应
* BS 架构和 CS 架构并非对立存在，比如现代浏览器上既可以存在 BS 模式，也可以使用 websocket 来实现 CS 架构

## 通信协议

* BS 架构使用 http 协议来进行通信
* CS 架构使用 socket 或者自定义协议来实现通信

## 兼容性和扩展性

* BS 的兼容性和扩展性更好，只要设备有浏览器，就能用同一套的代码
* CS 的应用则需要考虑不同设备的兼容，在物联网这类应用广泛


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaobaiha.gitbook.io/tech-share/engineering/bs-jia-gou-yu-cs-jia-gou.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
