Home > Backend Development > PHP Tutorial > PHP interview question 2: Transmission protocols used

PHP interview question 2: Transmission protocols used

不言
Release: 2023-03-24 09:16:02
Original
4307 people have browsed it

The content of this article is about the transmission protocol used in the second PHP interview question. It has a certain reference value. Now I share it with you. Friends in need can refer to it

1.HTTP (hyper text transport protocol): Hypertext transfer protocol. It is one of the most widely used communication protocols on the Internet. WWW programs used by Internet users need to comply with this protocol standard. If a user wants to access files on a certain resource server, including browsing, downloading, running, etc. specified files on the server, they can access WWW resources on the Internet through HTTP.
 2. FILE: Local file transfer protocol. It is a method of obtaining files from the user's own computer, through which the user can display the files saved on his own hard disk on the screen of the navigation system.
 3. FTP (file transfer protocol): File transfer protocol. This protocol is one of the methods for obtaining files from the Internet. It serves to transfer files between users and file servers. Through this protocol, users can easily view the file content on the remote server, and at the same time, they can copy the required content to the computer they are using. On the other hand, if the file server authorization allows users to use files on the server for management, the user can upload the content on his local computer to the file server for other users to share, and can freely modify the above files. Edit files, such as deleting, moving, copying, renaming, etc.

The transport layer provides two ways to reach the target network

Transmission Control Protocol (TCP): Provides complete error control and flow control to ensure normal data transmission. It is a connection-oriented agreement.
User Datagram Protocol (UDP): It only provides basic error detection and is a connectionless protocol.
Features:
1) UDP:
Package data
Data size is limited (64k)
Do not establish connection
Fast speed, but low reliability
2)TCP :
Establish a connection channel
Unlimited data size
Slow speed, but high reliability
Because the transport layer involves many things, such as ports, Sockets, etc., we need to understand them for mobile development , we will introduce it in detail in subsequent articles, so we will not explain it here.

The application layer, as the highest level of the TCP/IP protocol, is the most exposed for our mobile development.

Protocol running on TCP protocol:
HTTP (Hypertext Transfer Protocol, Hypertext Transfer Protocol), mainly used for ordinary browsing.
HTTPS (Hypertext Transfer Protocol over Secure Socket Layer, or HTTP over SSL, Secure Hypertext Transfer Protocol), a secure version of the HTTP protocol.
FTP (File Transfer Protocol), as its name implies, is used for file transfer.
POP3 (Post Office Protocol, version 3, post office protocol), used for receiving mail.
SMTP (Simple Mail Transfer Protocol, Simple Mail Transfer Protocol), used to send emails.
TELNET (Teletype over the Network, network telex), log in to the network through a terminal.
SSH (Secure Shell, used to replace TELNET with poor security), used for encrypted and secure login.
Protocol running on UDP protocol:
BOOTP (Boot Protocol, startup protocol), applied to diskless devices.
NTP (Network Time Protocol, Network Time Protocol), used for network synchronization.
DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol), dynamically configures IP addresses.
Others:
DNS (Domain Name Service, domain name service), used to complete address lookup, mail forwarding, etc. (running on TCP and UDP protocols).
ECHO (Echo Protocol, wraparound protocol), used for error checking and measuring response time (running on TCP and UDP protocols).
SNMP (Simple Network Management Protocol, Simple Network Management Protocol) is used for network information collection and network management.
ARP (Address Resolution Protocol), used to dynamically resolve the address of Ethernet hardware.

sip protocol https://www.cnblogs.com/gardenofhu/p/7299963.html

Session Initiation Protocol (SIP) is the most commonly used in VoIP technology One of the agreements. It is an application layer protocol that works in conjunction with other application layer protocols to control multimedia communication sessions over the Internet.

SIP - Overview
Here are a few things to note about SIP -

SIP is a signaling protocol used to create, modify and terminate multimedia sessions over the Internet Protocol. A session is nothing more than a simple call between two endpoints. The endpoint can be a smartphone, laptop, or any device that can receive and send multimedia content over the Internet.

SIP is an application layer protocol defined by the IETF (Internet Engineering Task Force) standard. It is defined in RFC 3261.

SIP embodies the client-server architecture and uses URLs and URIs of HTTP and the text encoding scheme and header styles of SMTP.

SIP employs the help of SDP (Session Description Protocol), which describes sessions and RTP (Real-Time Transport Protocol) for delivering voice and video over IP networks.

SIP can be used for two-party (unicast) or multi-party (multicast) sessions.

Other SIP applications include file transfer, instant messaging, video conferencing, online gaming, and streaming multimedia distribution.

The following figure illustrates the applicability of SIP in a general scenario -

Typically, the SIP protocol is used for Internet telephony and multimedia distribution between two or more endpoints. For example, one person can use SIP to initiate a phone call to another person, or someone can set up a conference call with many participants.

The design of the SIP protocol is very simple, with limited configuration commands. It's also text-based, so anyone can read SIP messages passed between endpoints in a SIP session.

There are entities that help SIP create its network. In SIP, each network element is identified by a SIP URI (Uniform Resource Identifier), which is like an address. Following are the network elements -

User Agent
Proxy Server
Registration Server
Redirect Server
Location Server
User Agent
It is the endpoint and most of the SIP network One of the important network elements. Endpoints can start, modify or terminate sessions. The user agent is the most intelligent device or network element in the SIP network. It can be a softphone, mobile phone or laptop.

The user agent is logically divided into two parts -

User Agent Client (UAC) - the entity that sends the request and receives the response.

User Agent Server (UAS) - The entity that receives requests and sends responses.

SIP is based on a client-server architecture, where the caller's phone acts as the client that initiates the call, and the called party's phone acts as the server that responds to the call.

Proxy Server
The network element receives requests from the user agent and forwards them to another user.

Basically a proxy server acts like a router.

It has some intelligence to understand the SIP request and send it with the help of URI.

The proxy server is located between two user agents.

There can be up to 70 proxy servers between the source and destination.

There are two types of proxy servers -

Stateless proxy server - it just forwards received messages. This type of server does not store any call or transaction information.

Stateful Proxy Server - This type of proxy server keeps track of every request and response received and can use it in the future if needed. If the other party does not respond, it can resend the request.

Registration Server
The registration server accepts registration requests from user agents. It helps users authenticate themselves in the network. It stores the URI and user's location in the database to help other SIP servers within the same domain.

Look at the example below, showing the process of SIP registration.

Here the caller wants to register with the TMC domain. Therefore, it sends a REGISTER request to the TMC's Registrar server, and the server returns a 200 OK response when authorizing the client.

Redirect Server
The redirect server receives the request and looks up the intended recipient of the request in the location database created by the registrar.

The redirect server uses the database to obtain location information and responds to the user with 3xx (redirect response). We'll discuss response codes later in this tutorial.

Location Server
The Location Server provides information about a caller's possible location to redirect and proxy servers.

Only proxy servers or redirect servers can contact location servers.

The following diagram depicts the role each network element plays in establishing a session.

SIP - System Architecture
SIP is structured as a layered protocol, which means that its behavior is described in terms of a fairly independent set of processing stages, with only loose coupling between each stage.

The lowest layer of SIP is its syntax and encoding. Its encoding is specified using enhanced Backus-Naur tabular syntax (BNF).

The second layer is the transport layer. It defines how a client sends a request and receives a response, and how the server receives a request and sends a response over the network. All SIP elements contain a transport layer.

Next is the transaction layer. A transaction is a request sent by a client transaction (using the transport layer) to a server transaction, and all responses to that request sent back to the client from the server transaction. Any task completed by the User Agent Client (UAC) will be done using a series of transactions. Stateless proxies do not contain a transaction layer.

The layer above the transaction layer is called a transaction user. With the exception of stateless proxies, every SIP entity is a transaction user.

The following figure shows the basic call flow of a SIP session.

The following is a step-by-step explanation of the above call flow -

The INVITE request sent to the proxy server is responsible for starting the session.

The proxy server sends 100 to try to respond to the caller (Alice) immediately to stop the resending of the INVITE request.

The proxy server searches for Bob's address in the location server. After obtaining the address, further forward the INVITE request.

After that, the 180 ring (temporary response) generated by Bob's phone is returned to Alice.

A 200 OK response is generated quickly after Bob picks up the phone.

Once the 200 OK reaches Alice, Bob receives an ACK from Alice.

At the same time, the session is established and RTP packets (session) start flowing from both ends.

After the session ends, any participant (Alice or Bob) can send a BYE request to terminate the session.

BYE directly from Alice to Bob bypassing the proxy server.

Finally, Bob sends a 200 OK response to confirm BYE, and the session is terminated.

In the above basic call flow, three transactions (labeled 1, 2, 3) can be used.

The complete call (from INVITE to 200 OK) is called a dialogue Dialog.

SIP Ladder
How does a proxy help one user connect with another user? Let’s find out with the help of the image below.

The topology shown in the figure is called SIP ladder diagram. The process happens as follows -

When the caller initiates a call, an INVITE message is sent to the proxy server. After receiving the INVITE, the proxy server attempts to resolve the recipient's address with the help of a DNS server.

After getting the next route, the caller's proxy server (Proxy 1, also known as the outbound proxy server) forwards the INVITE request to the callee's inbound proxy server (Proxy Server 2) The callee's proxy server.

The inbound proxy server contacts the location server to obtain the called party address information registered by the user.

After getting the information from the location server, forward the call to its destination.

Once the user agent knows their address, they can bypass the call, i.e. speak directly.

SIP messages are of two types - request and response.

The start line of the request contains the method that defines the request, and the request URI that defines the request to be sent.

Similarly, the beginning line of the response contains the response code.

Request method
SIP request is the code used to establish communication. To complement them, SIP responses usually indicate whether the request succeeded or failed.

These SIP requests, known as METHODS, enable SIP messages.

methods can be considered SIP requests because they request a specific action to be taken by another user agent or server.

Methods are divided into two types -

Core methods

Extension methods

Core methods
There are six core methods as described below .

INVITE
INVITE is used to initiate a session with the user agent. In other words, the INVITE method is used to establish a media session between user agents.

INVITE can include the calling party's media information in the email body.

If the INVITE has received a successful response (2xx) or an ACK has been sent, the session is considered established.

A successful INVITE request establishes a conversation between the two user agents, and the session cannot be terminated until BYE is sent.

An INVITE sent within an established dialog box is called re-INVITE.

Re-INVITE is used to change session properties or refresh the state of the dialog box.

Invitation example
The following code shows how INVITE is used.

Copy code

INVITE sips:Bob@TMC.com SIP/2.0  
  Via: SIP/2.0/TLS client.ANC.com:5061;branch = z9hG4bK74bf9  
  Max-Forwards: 70  
  From: Alicesips:Alice@TTP.com;tag = 1234567  
  To: Bobsips:Bob@TMC.com 
  Call-ID: 12345601@192.168.2.1 
  CSeq: 1 INVITE  
  Contact: sips:Alice@client.ANC.com  
  Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY  
  Supported: replaces  
  Content-Type: application/sdp  
  Content-Length: …
v = 0  
  o = Alice 2890844526 2890844526 IN IP4 client.ANC.com  
  s = Session SDP  
  c = IN IP4 client.ANC.com  
  t = 3034423619 0  
  m = audio 49170 RTP/AVP 0  
  a = rtpmap:0 PCMU/8000
Copy after login

Copy code

BYE 
BYE是用于终止既定会话的方法。这是SIP请求,可以由呼叫者或被叫方发送以终止会话。
它不能由代理服务器发送。
BYE请求通常路由端到端,绕过代理服务器。
BYE不能发送到待处理的INVITE或未建立的会话。
注册 
REGISTER请求执行用户代理的注册。该请求由用户代理发送到注册服务器。
REGISTER请求可以转发或代理,直到它到达指定域的权威注册商。
它在正在注册的用户的To头中携带AOR(记录地址)。
REGISTER请求包含时间段(3600sec)。
一个用户代理可以代表另一个用户代理发送REGISTER请求。这被称为第三方注册。这里,From标签包含代表To标题中标识的方提交注册的方的URI 。
取消 
CANCEL用于终止未建立的会话。用户代理使用此请求取消之前发起的未决呼叫尝试。
它可以由用户代理或代理服务器发送。
CANCEL是逐跳请求,即它通过用户代理之间的元素,并接收下一个有状态元素生成的响应。
ACK 
ACK用于确认对INVITE方法的最终响应。如果INVITE不可用,则ACK始终沿着INVITE.ACK的方向包含SDP主体(媒体特性)。
ACK可能不会用于修改已经在初始INVITE中发送的媒体描述。
接收ACK的有状态代理必须确定ACK应该向下游转发到另一个代理或用户代理。
对于2xx响应,ACK是端到端的,但对于所有其他最终响应,它在涉及有状态代理时基于逐跳的工作。
OPTIONS 
OPTIONS方法用于向用户代理或代理服务器询问其功能并发现其当前的可用性。对请求的响应列出了用户代理或服务器的功能。代理从不生成OPTIONS请求。
Copy after login

Extension method
Subscription
User agents use SUBSCRIBE to establish subscriptions to get notifications about specific events .

It contains an Expires header field indicating the duration of the subscription.

After the period, the subscription will be automatically terminated.

Subscription establishes a conversation between user agents.

You can resubscribe before the expiration time by sending another SUBSCRIBE within the dialog box.

Users subscribing will receive 200 OK.

Users can send another SUBSCRIBE method with Expires value 0 (zero) to cancel the subscription.

Notification
User agents use NOTIFY to get the occurrence of a specific event. Normally, NOTIFY will fire inside the dialog when there is a subscription between the subscriber and the notifier.

Each NOTIFY will get a 200 OK response if received by the notifier.

NOTIFY contains an event header field indicating the event and a subscriptionstate header field indicating the current state of the subscription.

Always send NOTIFY at the beginning and end of the subscription.

PUBLISH
PUBLISH is used by user agents to send event status information to the server.

PUBLISH is very useful when there are event information from multiple sources.

PUBLISH request is similar to NOTIFY, except it is not sent in a dialog box.

PUBLISH request must contain the Expires header field and the Min-Expires header field.

Reference
REFER is used by a user agent to refer to the URI of another user agent to access the dialog box.

REFER must contain the Refer-To header. This is the mandatory header for REFER.

REFER can be sent inside or outside the dialog box.

A 202 Accepted will trigger a REFER request, indicating that the reference has been accepted by other user agents.

Information
INFO is used by a user agent to send call signaling information to another user agent with which it has established a media session.

This is an end-to-end request.

The proxy will always forward INFO requests.

UPDATE
If the session is not established, UPDATE is used to modify the status of the session. Users can change the codec using UPDATE.

If the session is established, use re-invite to change/update the session.

PRACK
PRACK is used to acknowledge receipt of a reliable provisional response transfer (1XX).

Generally speaking, PRACK is generated by the client when receiving a provisional response containing an RSeq reliable sequence number and a supported:100rel header.

PRACK contains the (RSeq CSeq) value in the race header.

The PRACK method works for all temporary responses except 100-attempt responses, which are never reliable for transport.

PRACK may contain a message body; it can be used for offer/reply exchanges.

Message
It is used to send instant messages using SIP. IM typically consists of short messages exchanged in real time by participants involved in a text conversation.

MESSAGE can be sent within or outside the dialog box.

The content of MESSAGE is loaded in the email body as a MIME attachment.

A 200 OK response is received normally to indicate that the message has been delivered at its destination.

Related recommendations:

php interview question 1: The difference between threads and processes (by the way, coroutines are mentioned)

The above is the detailed content of PHP interview question 2: Transmission protocols used. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template