May 29 Service Interface

Source: Internet
Author: User

Interface:

The interfaces are divided into two categories :

object-oriented interfaces and often-called calling interfaces ,

An object-oriented interface is an abstract class (abstract class: The comparison abstraction cannot be directly new requires subclasses to implement specific operations, need to be inherited) and the interface is more abstract than the abstract class, the keyword used is more special interface

SOCKET:TCP, Long connection------

 The socket is the encapsulation and application of the TCP/IP protocol (at the programmer level).

It can also be said that the TPC/IP protocol is a transport layer protocol, mainly to solve how the data in the network transmission,

HTTP is an application-layer protocol that primarily addresses how data is packaged.

TCP: Long connection, client initiates connection to server, server accepts client connection, both sides establish connection. After the client and server have completed a read and write, the connection between them is not actively closed, and subsequent read and write operations continue to use the connection.

HTTP: Stateless. Each request will be disconnected. Establishing a new disconnect, establishing a disconnect-----HTTP protocol is a stateless protocol

Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. On the other hand, it responds faster when the server does not need the previous information.

<?PHP//The parent class must be overridden in an interfaceInterfaceUsb//cannot be directly new through subclasses{    functionRead () {}functionWrite () {}}classUpanextendsusb{functionRead () {Echo"Read USB"; }    functionWrite () {Echo"Write USB data"; }    }?>
Example:use API interface to query weather forecast, API: Call the interface to give its data and return the data we need

National Weather forecast Interface API, according to the region name, latitude and longitude, IP query the corresponding region of the weather forecast. The interface returns 7 days of data, including daytime temperature, humidity, wind speed, wind direction, wind, carbon monoxide, nitrogen dioxide and other PM 2.6 Air quality index, clothing, travel, car wash and other life index. The 7-day weather forecast is updated 3 times a day, 9 points, 12 points, 18 points respectively. Real-time weather conditions are updated 1 times every 30 minutes.

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHP//MD5 Signature Method--non-simple signatureHeader("Content-type:text/html;charset=utf-8");d Ate_default_timezone_set ("PRC");$showapi _appid= ' 19667 ';//Replace this value and find the relevant value in my apps on the official website$showapi _secret= ' 5693007ca66f483cb14782b137745212 ';//Replace this value and find the relevant value in my apps on the official website  $PARAMARR=Array(     ' Showapi_appid ' =$showapi _appid, ' area ' = ' Qingdao '); //creating parameters (including processing of signatures)functionCreateparam ($PARAMARR,$showapi _secret) {     $paraStr= ""; $signStr= ""; Ksort($PARAMARR); foreach($PARAMARR  as $key=$val) {         if($key! = ' &&$val! = ") {             $signStr.=$key.$val; $paraStr.=$key.‘ = '.UrlEncode($val).‘ & '; }     }     $signStr.=$showapi _secret;//sorted parameters plus secret for MD5     $sign=Strtolower(MD5($signStr)); $paraStr. = ' showapi_sign= '.$sign;//The MD5 values are used as parameters to facilitate the server's validation//echo "sorted parameters:". $paraStr. " <br> ";     return $paraStr;} $param= Createparam ($PARAMARR,$showapi _secret);$url= ' http://route.showapi.com/9-2? '.$param; //echo "Requested URL:". $url. " <br> ";$result=file_get_contents($url);Echo"Returned JSON data:";$result= Json_decode ($result);//Var_dump ($result); Returns object//converts an object to an array$attr= Object_array ($result);functionObject_array ($array){    if(Is_object($array))    {        $array= (Array)$array; }    if(Is_array($array))    {        foreach($array  as $key=$value)         {            $array[$key] = Object_array ($value); }    }    return $array;}Echo"Today's maximum temperature is: {$attr[' Showapi_res_body '] [' F1 '] [' Day_air_temperature ']} ";//Query Maximum temperatureVar_dump($attr);?></body>View Code

Add:

TCP(transmission Control Protocol Transmission Protocol) is a connection-oriented, reliable, byte-stream-based Transport layer communication protocol that, in the simplified computer network OSI model, accomplishes the functions specified by the fourth layer of the Transport layer, The User Datagram Protocol (UDP) is another important transport protocol within the same layer [1]. In the Internet Protocol family (Internet Protocol suite), the TCP layer is the middle tier located above the IP layer and below the application layer. There is often a need for reliable, pipe-like connections between the application tiers of different hosts, but the IP layer does not provide such a flow mechanism, but rather provides unreliable packet switching.

When the TCP protocol is used in network communication, before the actual read and write operation, the server and the client must establish a connection, when the read and write operation is completed, the two sides no longer need the connection when they can release the connection, the connection is established to need three handshake, and release will require 4 handshake, So the establishment of each connection requires resource consumption and time consumption.

HTTP Hypertext Transfer Protocol (HTTP, hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet. All WWW documents must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages.

After the advent of Web applications in which clients interact dynamically with the server, HTTP stateless features seriously hinder the implementation of these applications, after all, the interaction needs to be followed, and the simple shopping cart program knows what the user has chosen before. As a result, two techniques for keeping the HTTP connection state are created, one is a Cookie and the other is a Session. HTTP itself is a stateless connection protocol, in order to support the interaction between the client and server, we need to use different technologies for the interactive storage state, and these different technologies are the cookie and session.

May 29 Service Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.