05 MU class Network "Attack on node. JS Foundation (i)" HTTP concept advanced

Source: Internet
Author: User

HTTP Module Introduction

More features that support the HTTP protocol

Do not cache requests and responses

API comparison of the underlying processing flow-related, information analysis

HTTP related concept callbacks

The function is passed as a parameter to the execution function, and the parameter function is nested in the execution function.

function Learn (something) {    console.log (something);} function We (callback,something) {    something+ = ' is cool '    callback (something)}// named function We (Learn, ' Nodejs ')// anonymous functions We (function(something) {    Console.log (Something)},' Hello ')

Synchronous/Asynchronous

asynchronous functions in JavaScript

// Executes once SetTimeout (function() {   alert (' 1 ')},2000) within the specified interval
// repeated execution within the execution interval, but the alert needs to be closed without popping n setinterval (function() {   alert (' 1 ')}, 2000)

Synchronous

The task is executed sequentially, waiting for the previous execution to complete before executing the next

// Sync var c=0function  print () {    console.log (c)}function  Plus () {    SetTimeout (function() {        console.log (' aaa ')    },+)    C +=1;} Plus () print ()

Asynchronous

Each task has multiple callback functions, and the previous task does not perform the next task, but instead executes the callback function, and the latter task executes in the order in which the task is sorted, not waiting for the previous task to complete

// asynchronously executes the callback function after the task execution completes var c=0function  print () {    console.log (c)}function  Plus (callback) {    SetTimeout (function() {        c+=1;        Callback ()    },    console.log (' a ')}plus (print)

/ o

Data read and write on disk

Single Thread/multithreading

Only one request and response can be made at a time

Multiple requests and responses at the same time

Blocking/non-blocking

Blocking: Client waits for service side response

Non-blocking: The request does not respond to the other, after a period of time to request

Event

Click, move, and other actions

Event-driven

function is executed when the event occurs

Event-driven callbacks

callback function in the function

Event Loops

Dense task asynchronous execution put into loop queue, single thread constantly querying loop queue

05 MU class Network "Attack on node. JS Foundation (i)" HTTP concept advanced

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.