13.3 Network Programming example
"Practice out of the truth", so in the technical study, or need to do a lot of practice, can realize the mystery of technology, the following through two simple examples to demonstrate the actual use of network programming.
13.3.1 Prime number Discriminant Example
This
First code: Less codeThrough regular expression to get the real address of Baidu Network disk, to achieve the effect of direct chain
Save the following code as downbd.php
Copy Code code as follows:
$canshu =$_server["Query_string"];
if ($canshu = = "")
{
Text/Jiang Tao
Application description
This code implements the RFC 868 client. Start the program and establish a TCP connection to the given time service. The time service returns a four-byte integer, which is the number of seconds from on January 1, January 1, 1900 to the past time, of course, it is in the order of network bytes. After the network bytes are co
("When the server-side character is received as \" Ok\ ", the client terminates \ n"); while(true) {Socket socket =NULL;Try{//Create a stream socket and connect it to the specified port number on the specified hostSocket =NewSocket (IP_ADDR, PORT);//Read server-side dataDataInputStream input =NewDataInputStream (Socket.getinputstream ());//Send data to server sideDataOutputStream out =NewDataOutputStream (Socket.getoutputstream ()); System.out.println ("Client input:"); String str =NewBufferedR
Read the importance of source code: for example, the chef selects food ingredients and plays kitchen utensils-how to view the Java and Android source code in Eclipse, eclipseandroid
First of all, many people say that they will not learn Java without looking at the source
13.3.2 Guess number Games
The following example is a console game for guessing numbers. The rule of the game is: when the client first connects to the server side, the server side produces a " Random numbers between the 0,50", then the client input numbers to guess the number, each time the client input number, sent to the server side, the server to determine the client sent the number and the relationship between the random number, and feedback comp
Java programming example of Pascal triangle code, java Pascal
Source program exposure
Yang Hui triangle properties:
Each line of numbers is symmetric between the left and right, and gradually increases from 1, then decreases, and returns to 1.The number of numbers in the nth row is n.The number in line n is 2 ^ (n-1 )
Java programming multi-thread problem example code, java multi-thread
In the previous blog posts, I have summarized some content in java concurrency. This blog post mainly starts from a problem and shows which concurrency technologies can be used to solve the problem.Descrip
The java code is as follows:
// Listing 33 A Java Code Example
// Java
// Create new writer document and get text, then manipulate text
XComponent xWriterComponent = newDocComponent ("swriter ");
XTextDocument xTextDocument = (XTe
MD5 and RSA are the two most commonly used algorithms in network transmission. After understanding the principles of these two algorithms, you can get a general idea of what encryption is like. However, these two algorithms use different environments and are just complementary.
I. MD5 Algorithm
First, MD5 is irreversible and can only be encrypted but cannot be decrypted. For example, if the plaintext value
Reference fromHttp://www.cnblogs.com/tianzhijiexian/p/3906774.htmlHttps://github.com/tianzhijiexian/HttpAnnotation/blob/master/lib/src/main/java/kale/net/http/util/HttpReqAdapter.javaOriginal webpage address: http://www.codeceo.com/article/java-reflector.html ...Summary: The simplest and most elegant use of reflection.Examples of this article can be seen in the sample c
This article will be from the traditional bio to NiO to the AIO from the shallow to the deep introduction, and enclose the complete code explanation.
This example is used in the following code: The client sends a formula string to the server, and the server evaluates the result to the client.
All the instructions for the code
ChannelsWe read and write to the data through the channel, it is like a water pipe, is a channel. The channel differs from the flow where the channel is bidirectional and can be used for read, write, and simultaneous reading and writing operations.The channels of the underlying operating system are generally full-duplex, so full-duplex channel streams can better map the underlying operating system's APIs.There are two major types of channel:
Selectablechannel: User
Reprint please indicate the source: http://blog.csdn.net/anxpp/article/details/51512200, thank you.
This article will be from the traditional bio to NiO to the AIO from the shallow to the deep introduction, and enclose the complete code explanation.
This example is used in the following code: The client sends a formula string to the server, and the server evaluat
http://my.oschina.net/kingfire/blog/156764OverviewRemote Power On (Wake Onlan) refers to the network implementation of the server or PC to start running, now a lot of network cards are supported by this feature. The simple principle is to send a specially formatted packet to the target host, and then start the system after the target host receives it.Specific methods.
Setting the BIOS on Wake Onlan
:
If a Thread-safe implementation is not needed, it's recommended to use HASHMAP in place of Hashtable. If a thread-safe highly-concurrent implementation is desired and then it's recommended to use Java.util.concurrent.Concurren Thashmap in place of Hashtable.
Simply put, if you don't need thread safety, then use HASHMAP, if you need thread safety, then use Concurrenthashmap. Hashtable has been eliminated, do not use it in the new code.8
bin = new Filebody (file);Stringbody encapsulates a parameter of type stringStringbody keybody = new Stringbody (key, Contenttype.text_plain);Stringbody typebody = new Stringbody (type, contenttype.text_plain);Addpart Pass the argument and specify the parameter nameHttpentity reqentity = Multipartentitybuilder.create (). Addpart ("Pic", bin). Addpart ("key", Keybody). Addpart ("Cardtype", Typebody). Build ();Httppost.setentity (reqentity);Httppost.setconfig (config);Perform
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.