20155335 Eucun "Java Programming" 10th Week summary

Source: Internet
Author: User
Tags hosting

Study number 2016-2017-2 "Java Program Design" Tenth Week Learning summary

##

In fact, network programming, we can simply understand the two computers to communicate with each other data, for programmers, master a programming interface and use a programming model is relatively simple, JAVASDK provides some relatively simple API to complete 12 of these tasks, socket is one of them, For Java, the presence of APIs and the java.net package inside. So as long as you import this package you can prepare for network programming.

Client-to-server model is the basic model of network programming, the simple is to introduce the communication between the two processes, one must provide a fixed position, two, and the other only need to know the fixed position, and to establish the communication between the two, and then complete the communication between the both can be, The location provided here is usually to become a server, establish a link to the commonly called client, give a simple model, you can enter the network programming.

In Java, there are a lot of APIs to support this model, one of the most typical is the socket programming interface, for Java has simplified the socket programming interface, we need to discuss how to provide fixed location of the service side is established, Java provides seversocket to support it, in fact, when we create an instance object of the class and provide a port resource to establish a fixed location, this location can be accessed by other computers.

Code:

Here the allocation of the port is unique, because the port is to uniquely identify each calculator unique service, the other port is to uniquely represent each calculator only service, the other port number is from 0~65535, the first 1024 ports have been TCP/IP as a reserved port, So the allocated port can only be 1024 after, with a fixed position, now what is required is a connection, the connection by the client side first provide the requirements, so Java also provides a socket object to support it, as long as the client side to create a socket instance object to support it.

Code:

Socket client = new socket (Inetaddress.getlocalhost (), 5678);

The client must know about the IP address of the server, for which Java provides some related classes inetaddress that an instance of the object must be provided by means of a static method, and the method of obtaining inetadress can be obtained directly through the IP of the machine and by name or IP , unless it is remotely dropped. The core of the processing problem is executing, otherwise the interaction of the data still depends on the IO operation.

These two basic methods can establish a connection, so that the two computers communicate with each other, the data must be transmitted, in fact, input/output operation is always related to network programming, because the underlying network can always continue to data, unless it is a remote call, you must import java. IO this package, java. The operation of Io is not complex, providing a reader and writer for Byte stream and Unicode, and then providing a buffer for reading and writing data.

Java code

BufferedReader in=new BufferedReader (New InputStreamReader (Sever.getinputstream ()));

PrintWriter out =new PrintWriter (Server.getoutputstream);

The above two sentences is to establish a buffer and the original byte flow into Unicode can be manipulated, and the original stream of bytes from the socket two methods, getInputStream () and Getoutputstream () side, respectively, to get input and output, Now that we have the basic model and the basic operating tools, we can do a simple socket process.

Import java.io*;

Import java.net*;

public class myserver{

public static void Main (string[] args) throws ioexpection{

Seversocket Server = new Seerversocket (5678);

Socket client=server.accept ();

\ bufferedreader in=

New BufferedReader (New InputStreamReader (Client.getinputstream ()));

Printerwriter out=new PrintWriter (Client.getoutputstream ());

while (ture)

{

String Str=in.readline ();

System.out.println (str);

Out.println ("has recesive ...");

Out.flush ();

If (Str.equals ("End"))

break;

}

Client.close ();

}

}

Hybrid cipher System

First, in academia, public cryptography has aroused excitement in the scientific community, and in the year of public cryptography, the NSA recommended the traditional encryption system designed by IBM as a federal data Encryption standard.

The real world proves that the public key algorithm does not replace the symmetric key algorithm, the public key algorithm does not have to encrypt the message, but uses the encryption key, this has two reasons:

(1). The public key algorithm is slower than the symmetric algorithm, in general, the speed of the symmetric algorithm is 1000 times times the public key algorithm

(2) The public key system is vulnerable to the selection of plaintext attacks. If C=e (p), when p is a clear text in n possible plaintext, the cipher parser only needs to encrypt all n possible plaintext and compare the result with C (the encryption key is public). In this way, it is not possible to recover the decryption key, but he can determine p.

(3) In most practices, the public key password is used to protect and distribute the session key, which in the symmetric algorithm, the communication message is confidential, sometimes called the communication system is a hybrid cipher system.

Summarize what you learned this week as simple as possible.

Try not to transcription, waste time

Read it, do not understand, learn to remember the experience

# # Problems and solutions in textbook learning

-Problem 1:xxxxxx

-Problem 1 Solution: XXXXXX

-Problem 2:xxxxxx

-Problem 2 Solution: XXXXXX

- ...

# # Problems in code debugging and resolution process

-Problem 1:xxxxxx

-Problem 1 Solution: XXXXXX

-Problem 2:xxxxxx

-Problem 2 Solution: XXXXXX

- ...

# # [Code Hosting] (Code Cloud Learning Project LINK)

Http://git.oschina.net/tianmaxingkomg/xinjianxianmu

(run result of statistics.sh script)

# # last week quiz summary of the wrong title

-Wrong question 1 and why, understand the situation

-Wrong question 2 and why, understand the situation

- ...

# # Pairs and mutual comments

# # # Scoring Standard

1. Correct use of markdown syntax (plus 1 points):

-Do not use markdown without extra points

-No extra points for grammatical errors (links cannot be opened, table is wrong, list is incorrect ...) )

-No extra points for typesetting confusion

2. Complete features in the template (plus 1 points)

-Lack of "problem in textbook learning and solution process" without extra points

-Lack of "problem in code debugging and resolution process" without extra points

-[Code Hosting] (link) cannot be opened 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 material" for no extra points

-Blog comments last week

-[Study No. 1] (blog link)

-[Study No. 2] (blog link)

-[Study No. 3] (blog link)

-[Study No. 4] (blog link)

- ...

# # Other (sentiment, thinking, etc., optional)

Xxx

Xxx

# # 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 |   300/1300 | 2/9 |       30/90 | |

Try to record "planned learning time" and "actual learning time" to see if you can improve your planning skills by the end of the semester. This work is very important and useful in learning.

Formula for time-consuming estimation

: y=x+x/n, y=x-x/n, the number of training, X, Y is close.

Reference: [Why is it so difficult to estimate a software engineering application] (http://www.cnblogs.com/xinz/archive/2011/04/05/2005978.html), [Software engineering estimation Method] (http:// www.cnblogs.com/xinz/archive/2011/04/06/2007294.html)

20155335 Eucun "Java Programming" 10th Week summary

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.