# 20155336 2016-2017-2 "Java Programming" Tenth Week study summary

Source: Internet
Author: User
Tags hosting server port

20155336 2016-2017-2 "Java Programming" Tenth Week Study Summary learning task
    • Complete Learning Resources related content

    • Refer to the above Learning summary template, the learning process through the blog (essays) published, blog title "Study Number 2016-2017-2" Java program design tenth weeks of study summary "

      • Deadline: This Sunday 24:00, not on time to send a blog to buckle 1 points, excellent blog plus 1 points

      • Non-plagiarism, violators included in the Licicunzhao-plagiarism operator's exposure table

Learning Content Summary Network programming
    • Network programming is the transfer of data between two or more than two devices, such as a computer. What the programmer is doing is sending the data to the specified location, or receiving the specified data. When sending and receiving data, most programming languages design specialized APIs to implement these functions, and programmers only need to invoke them.
Network overview
  • 1.1 Computer network Overview:

    照计算机网络的定义,通过一定的物理设备将处于不同位置的计算机连接起来组成的网络,这个网络中包含的设备有:计算机、路由器、交换机等等。路由器和交换机组成了核心的计算机网络,计算机只是这个网络上的节点以及控制等,通过光纤、网线等连接将设备连接起来,从而形成了一张巨大的计算机网络。为了能够方便的识别网络上的每个设备,网络中的每个设备都会有一个唯一的数字标识,这个就是IP地址。一个IP地址可以对应多个域名,一个域名只能对应一个IP地址。注意: 在硬件上规定,端口的号码必须位于0-65535之间,每个端口唯一的对应一个网络程序,一个网络程序可以使用多个端口。
  • 1.2 Network Programming Overview:

    网络编程就是两个或多个设备之间的数据交换,其实更具体的说,网络编程就是两个或多个程序之间的数据交换,和普通的单机程序相比,网络程序最大的不同就是需要交换数据的程序运行在不同的计算机上,这样就造成了数据交换的复杂。“请求-响应”模型:也就是通讯的一端发送数据,另外一端反馈数据,网络通讯都基于该模型。客户端/服务器结构:也叫做Client/Server结构,简称C/S结构。一旦通讯建立,则客户端和服务器端完全一样,没有本质的区别。这种结构的优势表现力丰富,而服务器端也需要专门进行开发。但是这种结构也存在着很多不足,例如通用性差,实际维护时,也需要维护专门的客户端和服务器端,维护的压力比较大。浏览器/服务器结构:也叫做Browser/Server结构,简称为B/S结构。 使用B/S结构的程序,在开发时只需要开发服务器端即可,这种结构的优势在于开发的压力比较小,不需要维护客户端。P2P(Point to Point)程序:是一种特殊的程序,应该一个P2P程序中既包含客户端程序,也包含服务器端程序。协议(Protocol):网络中传输的数据格式在网络编程中就被称作协议。
  • 1.3 Network communication mode:

    1、TCP(传输控制协议)方式 :TCP方式就类似于拨打电话,使用该种方式进行网络通讯时,需要建立专门的虚拟连接,然后进行可靠的数据传输,如果数据发送失败,则客户端会自动重发该数据。2、 UDP(用户数据报协议)方式:而UDP方式就类似于发送短信,使用这种方式进行网络通讯时,不需要建立专门的虚拟连接,传输也不是很可靠,如果发送失败则客户端无法获得。小结:重要的数据一般使用TCP方式进行数据传输,而大量的非核心数据则都通过UDP方式进行传递,在一些程序中甚至结合使用这两种方式进行数据的传递。由于TCP需要建立专用的虚拟连接以及确认传输是否正确,所以使用TCP方式的速度稍微慢一些,而且传输时产生的数据量要比UDP稍微大一些。
Network Programming Technology
  • 2.1 Network Programming steps

    The steps here are not language-independent, that is, this step applies to various language implementations.

  • 2.1.1 Client Network programming steps:

    • Establish a network connection: the first step in client network programming is to establish a network connection. When establishing a network connection, you need to specify the IP address and port number of the server to which you are connected, and after completion, a virtual connection is formed, and subsequent operations can be exchanged through the connection.
    • Exchange data: Once the connection is established, the data can be exchanged through this connection. Exchange data in strict accordance with the request response model, the client sends a request data to the server, the server feedback a response data to the client, if the client does not send the request, the server side will not respond. Depending on your logic needs, you can exchange data multiple times, but you still have to follow the request response model.
    • Shut down network connection: After the data exchange is complete, shut down the network connection, release the port, memory and other system resources, and end the network programming.
  • 2.1.2 Server-side network programming steps:

    • Listening Port: The server side is passive waiting for the connection, so after the server is started, you do not need to initiate the connection, but only need to listen to a fixed port on the local computer.
    • Get connected: When the client connects to the server side, the server can get a connection that contains information about the client, such as the client IP address, and so on, and the server side and the client also exchange data through the connection.
    • Exchange data: When the client connects to the server side, the server can get a connection that contains the client's information, such as the client IP address, and the server side and the client also exchange data through the connection.
    • Close connection: When the server program shuts down, the server side needs to be shut down, the port that the server listens to and the memory that consumes can be freed up by shutting down the server side, which realizes the close of the connection.
  • Java Network Programming Technology

    和网络编程有关的基本API位于java.net包中,该包中包含了基本的网络编程实现,该包是网络编程的基础。该包中既包含基础的网络编程类,也包含封装后的专门处理WEB相关处理类。一个基础的网络类——InetAddress类。该类的功能是代表一个IP地址,并且将IP地址和域名相关的操作方法包含在该类的内部。
  • TCP Programming

    如果发送的一方发送的数据接收方觉得有问题,则网络底层会自动要求发送方重发,直到接收方收到为止。在Java语言中,对于TCP方式的网络编程提供了良好的支持,在实际实现时,以java.net.Socket类代表客户端连接,以java.net.ServerSocket类代表服务器端连接。
  • UDP programming

    UDP(User Datagram Protocol),中文意思是用户数据报协议,方式类似于发短信息,是一种物美价廉的通讯方式,使用该种方式无需建立专用的虚拟连接。网络编程中也是这样,必须要求可靠传输的信息一般使用TCP方式实现,一般的数据才使用UDP方式实现。在Java API中设计的实现结构和TCP方式不太一样。当然,需要使用的类还是包含在java.net包中。在Java API中,实现UDP方式的编程,包含客户端网络编程和服务器端网络编程,主要由两个类实现:1、DatagramSocket类实现“网络连接”,包括客户端网络连接和服务器端网络连接。2、DatagramPacket类实现对于网络中传输的数据封装,也就是说,该类的对象代表网络中交换的数据。在UDP方式的网络编程中,无论是需要发送的数据还是需要接收的数据,都必须被处理成DatagramPacket类型的对象,该对象中包含发送到的地址、发送到的端口号以及发送的内容等。
Network protocol
    网络协议是指对于网络中传输的数据格式的规定。网络协议的实质也是客户端程序和服务器端程序对于数据的一种约定,只是由于以计算机    为基础,所以更多的是使用数字来代表内容,这样就显得比较抽象一些。    网络协议就是一种格式上的约定,可以根据逻辑的需要约定出各种数据格式,在进行设计时一般遵循“简单、通用、容易解析”的原则进行。    客户端程序需要完成的处理为:1、 客户端发送协议格式的生成2、 服务器端反馈数据格式的解析    服务器端程序需要完成的处理为:1、 服务器端反馈协议格式的生成2、 客户端发送协议格式的解析    网络协议格式是该程序最核心的技术秘密,因为一旦协议格式泄漏,则任何一个人都可以根据该格式进行客户端的编写,这样将影响服务器    端的实现,也容易出现一些其它的影响。
Problems in teaching materials learning and the solving process
    • First about the relationship between IP address and domain, do not understand the connection between, is IP contains domain? Or does the domain contain an IP address? This piece of knowledge has some problems on the computer network. I think this article compares the IP address and the domain to the mobile phone number and the mobile phone address list, a person can have many mobile phone number, but a mobile phone number can only have one person correspondence. Similarly, a domain name can correspond to many IP addresses, but an IP address can have only one IP address.
    • What is the same domain? Previously it was simple to talk about the relationship between the domain and the IP address, but the specific definition of the domain was not given. Baidu after the "domain" of the true meaning refers to the server control network on the computer can join the computer combination.
    • Is the question of agreement, what is the specific role of the agreement? After learning about this problem, the real role of the protocol is a format, for different computers, different programs have different data formats, and for this data format is the protocol.
Problems in code debugging and the resolution process
  Package cc.openhome;    Import java.net.*;                    public class Inetaddressdemo {public static void main (string[] args) {try{//Create object with domain name                    InetAddress Inet1 = Inetaddress.getbyname ("www.163.com");                    System.out.println (INET1);                    Create an object using IP inetaddress inet2 = inetaddress.getbyname ("127.0.0.1");                    System.out.println (Inet2);                    Get the native Address object inetaddress Inet3 = Inetaddress.getlocalhost ();                    System.out.println (INET3);                    Gets the domain name stored in the object String host = Inet3.gethostname ();                    System.out.println ("Domain name:" + host);                    Gets the IP String IP = inet3.gethostaddress () stored in the object;           System.out.println ("IP:" + IP); }catch (Exception e) {}}}  

About this code, is based on the learning material to operate over, but the first show failed, and then carefully look at the learning materials, Java This network InetAddress class must have a network connection to use.

  • For the TCP Programming Connection section, the Java.net.Socket class represents the client connection, and the Java.net.ServerSocket class represents the server-side connection. So establish a client network connection, which is the object that creates the socket type, which represents the network connection.

    Socket socket1 = new Socket(“192.168.1.103”,10000);Socket socket2 = new Socket(“www.blog.com”,80);

    About this code, Socket1 is to connect to the IP address is the 192.168.1.103 of the computer's port 10,000th, and Socket2 implementation is connected to the domain name is www.blog.com of the computer's port 80th, if the connection is established, the local network is not connected, or the server-side program is not open , an exception is thrown.

  • about how to reuse a socket connection? After looking at the material, in fact, it is very simple, after the establishment of the connection, the data exchange logic written into a loop can be. This way, the connection will not be closed as long as the loop does not end.

    Package Tcp;import java.io.; Import java.net.;   public class Mulsocketclient {public static void main (string[] args) {socket socket = NULL;   InputStream is = null;   OutputStream OS = null;   Server-side IP address String serverip = "127.0.0.1";   Server port port number int port = 10000;   Send content String data[] ={"First", "Second", "third"};            try {//Establish connection socket = new socket (serverip,port);            Initialize stream OS = Socket.getoutputstream ();            is = Socket.getinputstream ();            Byte[] B = new byte[1024]; for (int i = 0;i < data.length;i++) {//Send data os.write [I].getby                     TES ());                     Receive data int n = is.read (b);            Output Feedback Data System.out.println ("Server Feedback:" + new String (b,0,n)); }} catch (Exception e) {e.printstacktrace ();//Print exception information}finally{try {//close        Streams and connections             Is.close ();                     Os.close ();            Socket.close (); } catch (Exception e2) {}}}}

This code writes the logic of the data Exchange section to the contents of a for loop, so that you can establish a connection and sequentially send the data in the array to the server side. You can implement a multiplexed socket connection.

Code Hosting

Other (sentiment, thinking, etc., optional)
    这周是学习的内容是学习网络编程,已经到了java语言运用的地方了,很多知识点在其他的课堂上有接触,但发现还是有不足,这周的代码    更多的主要还是学习材料里的代码进行操作,自己的动手编译程序的水平还欠缺一点。虽然到了java运用的时候,但还是要把握好java语言    基本的知识点,这才是最重要的。
Rating Standard (10 points)
    1. From 0 minutes to 10 minutes.
    2. Correct use of markdown syntax (plus 1 points):
      • Do not use markdown do not add points
      • There are grammatical errors of no points (link cannot open, the table is wrong, the list is not correct ...) )
      • No extra points for typesetting confusion
    3. Complete features in the template (plus 1 points)

      • Lack of "The problem in teaching material learning and the solution process" without extra points
      • Lack of "problem in code debugging and resolution process" without extra points
      • Code hosting does not open without extra points
      • Lack of "pairing and mutual evaluation" cannot be opened without extra points
      • The lack of "Last week's exam error Summary" Cannot add points
      • Missing "progress bar" cannot be added
      • Lack of "reference" cannot be added
    4. Problem and solution process in textbook learning, one question plus 1 points

    5. Code debugging problems and resolution process, a problem plus 1 points

    6. Valid code for this week exceeds 300 branches (plus 2 points)

      • Less than 20 times a week of submissions

6 Other bonus points:-Friday ago Blog Add 1 points-impressions, experience not false big empty plus 1 points-beautifully typesetting plus a point-the progress bar record learning time and improve the addition of 1 points-have to write a new code plus 1 points-after-class selection with the validation of 1 points-code commit message specification plus 1 Points-Wrong topic learning in-depth plus 1 points 7 points:-There is a copy of the deduction to 0 points-code cheating deduction to 0 points

Reviews Template:
    • Based on the scoring criteria, I scored this blog: 10. The score is as follows:

      • Correct use of markdown syntax
      • Complete features in the template
      • The problem and the solution process in the textbook learning, a question adds 1 points, altogether two
      • Code debugging problems and resolution process, a problem plus 1 points, altogether two
      • Valid code for this week exceeds 300 branches (plus 2 points)
      • Feelings, experience is not false big empty plus 1 points
      • Add 1 points to write new code
      • Add 1 points to the Code commit message specification
      • After-class selection with validation plus 1 points

The 10 points, or is not enough to add ~ ~ ~

reviewed the classmates blog and code

20155304

20155301

20155315

20155220

20155219

Learning progress Bar
             | Lines of code (new/cumulative) |  Blog volume (Add/accumulate) | Learning time (NEW/cumulative) | Important growth | --------   | :----------------:|:----------------:|:---------------:  |:-----:|| Target |   5000 Rows | 30 Articles |       400 hours | || First week |   200/200 | 2/2 |       20/20 | || Second week |   300/500 | 2/4 |       18/38 | || Third week |   500/1000 | 3/7 |       22/60 | || Week Four |   800/1300 | 4/9 |       30/90 | || Week Five |   1800/2000 | 5/9 |       45/100 | || Week Six |   2400/3000 | 6/10 |       60/100 | || Seventh Week |   3100/4000 | 7/11 |       75/100 | || Eighth Week |   3700/4500 | 8/12 |       90/110 | || Nineth Week |   4300/5000 | 9/12 |       105/130 | || Tenth Week |   4800/5000 | 10/10 |    120/145 |   | 

Reference: Why is it so difficult to estimate software engineering applications, software engineering estimation methods

    • Planned study time: 21 hours

    • Actual learning time: 15 hours

    • Improve the situation: have time to look at the software engineer's ability self-evaluation table

Resources
    • Java Learning Notes (8th Edition)

    • Java Learning Note (8th Edition) Learning Guide

    • ...

# 20155336 2016-2017-2 "Java Programming" Tenth Week study summary

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.