Piglet's Android starter Road Day 8 Part 2

Source: Internet
Author: User

Piglet's Android starter Road Day 8 Part 2

An analysis of Android network programming--android access to network resources

--Reprint Please specify Source: Coder-pig



Introduction to this section:


In Part 1, we learned about the concepts of XML files that are used more in network interactions, and what is commonly used in Android

Parsing XML three different forms, respectively sax,dom,pull three different parsing methods, and in part 2 we will

Explain how our application gets the resources on the web, namely images, HTML code, XML code, and JSON data.

All right, that's all you have to do, start the lesson in this section! Starting with this part, we need to use Tomcat to build the server.

is to build your own web program, you can create a Web program using eclipse directly or by downloading another myeclipse

In addition, the use of the website provided by the packaged Android IDE is not created Web programs, remember!



for beginners Looking at this article:

See here to prove that you have learned the majority of Android knowledge, the first congratulations to you! But there is also a problem to learn here!

said is the network, then inevitably involves the server and client interaction, for beginners, more questions are Service Side

the construction problem , after all, a lot of friends have not contacted the server, or the programming of servers! I'm stuck here.

A few days, do not know how to elaborate; Since many friends have not learned JSP and servlet or other server-side programming languages, let alone

ssh Those frameworks, here's a the lowest base : To Mastering the ability to get and parse data from server feedback ,

Rather than care about the implementation of the server, in fact, in a lot of companies have dedicated people to take charge of this piece of servers! Of course, if

If you ask for high, you can also teach yourself the simple JSP and servlet, of course, you can learn the next Java EE or other

The language of the server!

Because space is limited, may this article elaboration is not complete, to this article some content, the author may some do not understand, but please oneself manually knocks over,

Do not understand the knock again, the process of knocking to understand, do not know to knock two times, slowly drip you will have a harvest! directly behind the article

The Web project provided is loaded onto Tomcat, in addition, the IP must be changed Oh! In the Start menu, enter "cmd" and enter the instruction "ipconfig"

Find IPV4 that IP is!


Also provide some references (interested can be downloaded to see):

This article refers to the book: "Android 4.0 Network Programming": Http://pan.baidu.com/s/1o6siI6I

Reference Video: Http://pan.baidu.com/s/1jGiN3gE

After the ps:4.0 version, the Android network access operation cannot be done in the sub-thread! Need to create a new thread Oh!

In addition to access network operations, in fact, it is recommended to use the Vollery framework, interested in the words of their own understanding of the next!



Learning Roadmap for this section:



Body:



Flowchart of the HTML protocol:



Flowchart Analysis:

1) The user enters the Baidu domain name in the browser, after clicking accesses, the domain name sends to the DNS first, resolves the domain name, obtains the IP to link to the server corresponding

Port number (which is typically used to listen for client connection servers)!

2) Use the simplest TCP/IP protocol from the browser to the service area port, using the socket to complete

3) The data returned from the server has three forms, html,xml or JSON, and the user uploads or downloads the file using javase IO technology.






get pictures on the web

:



Code parsing:









get the page code on your network

:



PS: In addition to supporting HTML, other php,.net can read


Code parsing:










parsing the XML data returned by the server

:

To set up a good server platform, after the establishment of the Tomcat to run the message:


After accessing this link, the following XML content appears stating that the server has been built!

Then write the client, implemented as follows:




Code parsing:













parse the JSON data returned by the server

:

To set up a good server platform, after the establishment of the Tomcat to run the message:


After accessing this link, the following XML content appears stating that the server has been built!

Then write the client, implemented as follows:


Code parsing:









Reference code Download:

① get pictures on the Internet:http://pan.baidu.com/s/1eQ1SyA2

② get the Web code on the Internet:Http://pan.baidu.com/s/1sjJgYPB

③ gets the XML data returned by the server:Http://pan.baidu.com/s/1mgwW4sC

④ gets the JSON data returned by the server:http://pan.baidu.com/s/1pJyms0j

⑤web Project (service side):Http://pan.baidu.com/s/1hqGb5eW











Piglet's way to get started Day 8 Part 2

Related Article

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.