使用 http 协议而不是 TCP 启动 rails 服务器

Start rails server with http protocol instead of TCP

我是 ruby 和 rails 的新手。我正在处理 windows 10。Rails 服务器在 tcp://0.0.0.0:3000 而不是 http://localhost:3000 上启动。我正在使用以下命令。

rails server

我认为您对网络中的一些基础知识有点困惑。我会借此机会向您澄清这一点。

基于开放系统互连模型(OSI 模型)https://en.wikipedia.org/wiki/OSI_model

通信功能有7层标准化。

TCP 在 Transport layer

The transport layer provides the functional and procedural means of transferring variable-length data sequences from a source to a destination host, while maintaining the quality of service functions.

The transport layer controls the reliability of a given link through flow control, segmentation/desegmentation, and error control. Some protocols are state- and connection-oriented. This means that the transport layer can keep track of the segments and re-transmit those that fail delivery. The transport layer also provides the acknowledgement of the successful data transmission and sends the next data if no errors occurred. The transport layer creates segments out of the message received from the application layer. Segmentation is the process of dividing a long message into smaller messages.

OSI defines five classes of connection-mode transport protocols ranging from class 0 (which is also known as TP0 and provides the fewest features) to class 4 (TP4, designed for less reliable networks, similar to the Internet). Class 0 contains no error recovery, and was designed for use on network layers that provide error-free connections. Class 4 is closest to TCP, although TCP contains functions, such as the graceful close, which OSI assigns to the session layer. Also, all OSI TP connection-mode protocol classes provide expedited data and preservation of record boundaries. Detailed characteristics of TP0-4 classes are shown in the following table:

HTTP 位于 Application layer

The application layer is the OSI layer closest to the end user, which means both the OSI application layer and the user interact directly with the software application. This layer interacts with software applications that implement a communicating component. Such application programs fall outside the scope of the OSI model. Application-layer functions typically include identifying communication partners, determining resource availability, and synchronizing communication. When identifying communication partners, the application layer determines the identity and availability of communication partners for an application with data to transmit. The most important distinction in the application layer is the distinction between the application-entity and the application. For example, a reservation website might have two application-entities: one using HTTP to communicate with its users, and one for a remote database protocol to record reservations. Neither of these protocols have anything to do with reservations. That logic is in the application itself. The application layer per se has no means to determine the availability of resources in the network.

这意味着 TCP 不是 HTTP。基本上,HTTP(第 7 层)建立在 TCP/IP(第 4 层)之上。

https://en.wikipedia.org/wiki/Transmission_Control_Protocol https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

当您的 Rails 服务器说它在 tcp://localhost:3000 上启动时,这实际上意味着 http://localhost:3030 , and on Windows machines you have to use http://127.0.01:3030 而不是 Windows 以某种方式搞砸了。魔法!