WebService and Soap
HTTP is only responsible for transmitting the data in the past, not the data is XML, HTML, pictures, text files or anything else. and the SOAP protocol defines how to make an object into XML text, how to call it in a remote way, and how to confuse it.
Two kinds of protocols are said:
HTTP is the Post Office Protocol, they specify how you want your envelopes to be written, how many stamps to paste, etc...
Soap is the agreement between you and the person who is responsible for writing the meaning of what you need to express on the stationery, but also for the other party to be able to read your letter.
Web service is generally called by the SOAP protocol through HTTP, in fact, he is a WSDL document, customers can read the WSDL document to use this Web service. The customer describes the document according to the WSDL and generates a SOAP request message. Web service is placed behind a Web server (such as IIS), and customer-generated SOAP requests are embedded in an HTTP POST request and sent to the Web server. The Web server then forwards these requests to the Web Service request processor. The purpose of the request processor is to parse the received SOAP request, invoke the Web service, and then generate the corresponding SOAP reply. After the Web server has received a SOAP response, it is sent back to the client via an HTTP reply.
WebService protocol mainly includes two aspects: transport protocol and data representation, about the transport protocol can be HTTP or other, data representation can also be a key value pair, XML or other, but now the general is http+soap, of course, others can, do not know this understanding right?
Soap simple understanding, is such an open protocol Soap=rpc+http+xml: The use of HTTP as the underlying communication protocol; RPC as a consistent call path, XML as a data transfer format, Allows service providers and service customers to communicate over the Internet through a firewall.
TCP, Udp,ip
Network Fundamentals 1, OSI layered model and TCP/IP layered model correspondence relation
In this case, the 7-tier model is not expanded, only the knowledge points related to this series of topics are selected.
2, seven layer model and the corresponding relationship between the protocol
Network layer------------IP (interconnection protocol between networks)
Transport Layer------------TCP (Transmission Control Protocol), UDP (User datagram protocols)
Application tier------------Telnet (standard protocol and primary method for Internet Telnet service), FTP (Text Transfer Protocol), HTTP (Hypertext Transfer Protocol)
3. IP address and port number
1, the IP address is used to uniquely identify a communication entity in the network, the communication entity can be a host, can be a printer, or a router port. The packets that are transmitted in the IP-protocol network must be marked with an IP address. The IP address is like writing a letter, you must specify the recipient's address. Each transmitted packet includes a source IP and a destination IP.
2, the IP address uniquely identifies the communication entity, but a communication entity can have multiple communication programs to provide network services. This is the time to distinguish between specific communication programs by port. A communication entity cannot have two communication programs that use the same port number.
IP address and port number, like a trip to the field to stay in the hotel, the IP address indicates the location of the hotel, and the port number indicates the person's room number in the hotel.
4. TCP and UDP
1, TCP is a connection-oriented guarantee reliable transmission protocol. With the TCP protocol transmission, a sequential error-free data stream is obtained. It can provide reliable data flow between two computers, and applications such as HTTP, FTP, Telnet need this reliable communication channel.
2, UDP is a non-connected protocol, each datagram is a separate information, including the full source address or destination address, it on the network with any possible path to the destination, as to reach the destination, the time to reach the destination and the correctness of the content is not guaranteed.
Given the TCP protocol that guarantees reliable transmission, why not transmit the UDP protocol reliably? There are two reasons:
1, reliable transmission is to pay the price, the correctness of the data content of the test will inevitably occupy the computer processing time and network bandwidth. Therefore, TCP transmission efficiency is not as high as UDP.
2, many applications do not need to ensure strict transmission reliability, such as video conferencing system, does not require video audio data is absolutely correct, as long as it can be coherent. So in these scenarios, it's more appropriate to use UDP.
TCP,HTTP,UDP detailed
What are TCP and UDP, and what are the differences between them?
TCP is all called Transmission Control protocol. This protocol can provide connection-oriented, reliable, point-to-point communication.
The UDP full name is the User Datagram Protocol, which can provide non-connected unreliable point-to-multipoint communication.
With TCP or UDP, it depends on which aspect your program focuses on, whether it is reliable (TCP) or Fast (UDP).
The process of establishing a connection with TCP/IP
Mobile phone can use the network function is because the bottom of the mobile phone implementation of TCP/IP protocol, you can make the mobile phone terminal through the wireless network to establish a TCP connection.
TCP protocol can provide an interface to the upper network, so that the transmission of the upper network data is based on the "No Difference" network.
Setting up a TCP connection requires a "three-time handshake":
First handshake: The client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waiting for the server to confirm;
Second handshake: The server receives the SYN packet, it must confirm the customer's SYN (ACK=J+1), and also send itself a SYN packet (syn=k), that is, the Syn+ack packet, when the server enters the SYN_RECV state;
Third handshake: The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, and the handshake is completed three times.
The so-called three-time handshake is a Send/receive process that has three connection information. The establishment of a TCP connection requires the sending/receiving of three connection information.
The data is not included in the packets that are delivered during the handshake, and the client and server formally begin transmitting the data after the three handshake is complete. Ideally, once a TCP connection is established, the TCP connection is maintained until either side of the communication actively closes the connection. When disconnected, both the server and the client can initiate a request to disconnect the TCP connection, and the disconnection process requires a "four handshake" (the process is not fine-grained, that is, the server interacts with the client and finally determines the disconnection).
HTTP connection
The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web networking and one of the most commonly used protocols for mobile networking, an application built on the TCP protocol.
The most notable feature of an HTTP connection is that each request sent by the client requires a server loopback response, and the connection is actively released after the request has ended. The process from establishing a connection to closing a connection is called a "one-time connection."
1) in HTTP 1.0, each request from the client requires a separate connection to be established, and the connection is automatically freed after the request is processed.
2) in HTTP 1.1, multiple requests can be processed in a single connection, and multiple requests can overlap, without waiting for a request to end before sending the next request.
Because HTTP is actively releasing the connection after each request ends, the HTTP connection is a "short connection", which requires constant connection requests to the server to maintain the client program's online status. As a general practice, there is no need to obtain any data immediately, and the client will keep a "keep-connected" request to the server at regular intervals, and the server responds to the client after receiving the request, indicating that the client is "online". If the server can not receive the client's request for a long time, it is considered that the client "offline", if the client cannot receive a reply from the server for a long time, it is considered that the network has been disconnected.
Socket principle
In the iphone platform, to do socket development has open Source Library Asyncsocket, the official cfsocket, as well as BSD socket.
Socket (socket) concept
Socket (socket) is the cornerstone of communication and is the basic operating unit of network communication supporting TCP/IP protocol. It is an abstract representation of the endpoint in the network communication process and contains five kinds of information that must be used for network communication: the protocol that the connection uses, the IP address of the local host, the protocol port of the local process, the IP address of the remote host, and the protocol port of the remote process.
When the application layer communicates data through the transport layer, TCP encounters a problem that provides concurrent services for multiple application processes at the same time. Multiple TCP connections or multiple application processes may require data to be transmitted over the same TCP protocol port. To differentiate between different application processes and connections, many computer operating systems provide a socket (socket) interface for applications interacting with the TCP/IP protocol. The application layer can communicate with the transport layer through the socket interface, differentiate the communication from different application processes or network connections, and realize the concurrent service of data transmission.
Establishing a socket connection
Establishing a socket connection requires at least one pair of sockets, one running on the client, called Clientsocket, and the other running on the server side, called ServerSocket.
The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.
Server monitoring: Server-side sockets do not locate specific client sockets, but are waiting for the status of the connection, real-time monitoring network status, waiting for the client connection request.
Client request: Refers to the client's socket to make a connection request, to connect to the target is the server-side socket. To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.
Connection confirmation: When a server-side socket hears or receives a connection request from a client socket, it responds to a client socket request, establishes a new thread, sends a description of the server-side socket to the client, and once the client confirms the description, the two sides formally establish the connection. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.
Socket connection to TCP/IP connection
When you create a socket connection, you can specify the transport layer protocol used, which can support different transport layer protocols (TCP or UDP), which is a TCP connection when a connection is made using the TCP protocol.
Socket connection and HTTP connection
Since the socket connection is usually a TCP connection, once the socket connection is established, the communication parties can start sending data content to each other until the two sides are disconnected. However, in real network applications, the client-to-server communication often needs to traverse multiple intermediary nodes, such as routers, gateways, firewalls, and so on, most firewalls will turn off long inactive connections and cause the Socket connection to be disconnected, so it needs to be polled to tell the network that the connection is active.
The HTTP connection uses a "request-response" approach, not only to establish a connection at the time of the request, but also to be able to reply to the server after the client has made a request to the server.
In many cases, the server side is required to proactively push data to the client, keeping the client and server data in real time and in sync.
If the two sides set up a socket connection, the server can directly transfer data to the client;
If the two sides establish an HTTP connection, the server waits until the client sends a request before the data can be passed back to the client.
Therefore, the client periodically sends a connection request to the server, not only to remain online, but also to "ask" the server if there is new data, and if so, pass the data to the client.
HTTP protocol is the application layer of the semantic
One is the engine (Socket), which provides the ability of network communication
One is the sedan (Http), which provides a concrete way
The communication between the two computers is nothing more than the data communication between the two ports, and the specific information will be presented in the form of different application layer protocols, such as: http,ftp, ...
The socket is a tool for developing port communication, and it needs to be lower.
The difference and connection between socket and HTTP
1. Simply say that HTTP is generally one-way, if you like the server to initiate a request, the server will be back to you need, and the socket so that two-way, that is, one side (such as the client) changes will notify the other party (such as the server) requirements to be consistent, When this party (server) changes, it notifies the other party (the client) to keep the data consistent. In general, the program to maintain real-time (such as timely communication, stock software, etc.) with the socket is better, if the normal requirements of the real-time line is not high, the use of HTTP is enough, take it a bit for your program, depending on your situation.
2. "When we transmit data, we can only use the (Transport Layer) TCP/IP protocol, but in that case, if there is no application layer, it will not be able to identify the data content, if you want to make the transferred data meaningful, you must use to the Application layer protocol, the application layer protocol, such as HTTP, FTP, Telnet, etc., You can also define the application layer protocol yourself. The web uses the HTTP protocol as an application-layer protocol to encapsulate HTTP text information and then send it to the network using TCP/IP as the Transport layer protocol. ”
And we usually say the most socket is what, in fact, the socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API), through the socket, we can use the TCP/IP protocol. In fact, the socket is not necessarily associated with the TCP/IP protocol. The socket programming interface is designed to adapt to other network protocols as well. So, the advent of sockets just makes it easier for programmers to use the TCP/IP protocol stack, which is an abstraction of the TCP/IP protocol, thus forming some of the most basic function interfaces we know, such as Create, listen, connect, accept, send, Read and write, and so on. The network has a section on the socket and TCP/IP protocol relationship is relatively easy to understand:
"TCP/IP is just a stack of protocols, just like operating systems, which must be implemented in a specific way, as well as providing an external interface for operations." This is like the operating system will provide a standard programming interface, such as the Win32 programming interface, TCP/IP should also provide the interface for programmers to do network development, this is the socket programming interface. ”
CSDN has a comparative image of the description: HTTP is a sedan, providing a specific form of encapsulation or display data; the socket is the engine that provides the ability to communicate on the network.
In fact, the transport layer TCP is based on the network layer of IP protocol, and the application layer of the HTTP protocol is based on the transport layer of the TCP protocol, and the socket itself is not a protocol, as mentioned above, it just provides a TCP or UDP programming interface.
Web Service,soap, HTTP,TCP,UDP