java network programming instructions

java network programming refers to the network transport layer is based on Socket programming.

Network communication is the essence of the two independent host (a computer in the network does not depend on another computer.)
Ip address refers to a host logical address in the network, it can locate a host. IP address identifies the host location.

Strictly speaking, the host network communication is not communication, but the inter-process communication. A host such as the process there pa1, pa2 process, pa3 for, B hosts, there pb1 process, pb2 process, pb3 process. Process and the port number is bound to the relationship between, there are 0 host port number 65535, a process that can only bind a port. Binding after the end of the process to monitor the port number. IP address is like a phone number, port number is the extension.
Agreement: In order to smooth communication in advance to develop a number of conventions and standards, this is called agreement.
In network programming, there is a OSI seven layer model, bottom-up, will the network is divided into seven: Physical Layer - Data Link Layer - Network Layer - Transport Layer - Session Layer - presentation layer - the application layer. Every thing in order to complete their own, each will develop a number of agreements. Network layer is responsible for network addressing and routing, a network layer IP protocol. We are familiar with some of the protocols are application layer protocols. DNS name resolution protocol. POP3 is the Post Office Protocol. In the future to do network programming primarily refers to the application layer of the web programming, mainly based on HTTP protocol.

Transport layer problem is a safe and effective to transfer the data to the target host. Transport layer protocols:
1. TCP: Transmission Control Protocol, characteristics: is connected, safe and reliable, while the cost of the expense of efficiency, does not confirm the previous data, not by the next data. TCP is the most common transport layer protocol. TCP ensures that data is not lost and out of order. TCP is like a call.
2. UDP: User Datagram Protocol, a connectionless, unreliable. To spread into a number of data packets, and then click to send them out, but did not and objectives of the connection, the data routing may be different, this may cause data loss and out of order. UDP is more like writing, I can not say in what path the letter to the addressee by hand.

TCP protocol:
Socket: socket, a software programming model. An IP address plus a port (port), to uniquely specify a Socket. If the phone number ip, port is the extension, Socket is the telephone. Socket concept is proposed to simplify network communications. If the Socket is a telephone, the microphone is the output stream, input stream is the handset.

Network programming needs java** package.
ServerSocket ss = new ServerSocket (9000); this sentence running, my server process will bind the 9000 port number, it is possible that the port number that has been bound to another process, will be bound to fail.
ss.accept (); this is a blocking method, this will stop the main thread to wait for clients to connect over, this sentence is actually a process of listening, and if no one is connected, the server has been blocked. If a client to connect, Socket s = ss.accept () will return a Socket object.
To connect to the server to create a Socket object, to have two parameters: IP address and port number, IP address is a string type, you can write IP address, write the host name.
Instead of closing flow to be shut off Socket. You are responsible for applying the resources, you have to release. Socket comes with the flow, not that we created, we should shut to shut Socket.
Want to do many things at the same time a process, of course, to use multi-threading.
TCP uses two programming classes ServerSocket (server) and Socket (server and client). Server to use multiple clients to multiple threads.

UDP Protocol:
UDP is like writing letters, writing need paper, envelopes, boxes of three objects, programming in the paper in the UDP final String into a byte array corresponding to the envelope corresponding to the object is DatagramPacket, boxes corresponding to DatagramSocket.
DatagramSocket There are two ways: send, receive.
In the address in the UDP should use an object, said: InetAddress.
UDP protocol, the client sent a letter to come to the server, the server can send data to the client, as UDP is a connectionless protocol where.

TCP client is not connected to the same IP and UDP port of the server.

URL: Uniform Resource Locator. URL is a string that can define a resource on the network. The most common URL: ****sohu**/index.html. http is the protocol name, **sohu** is the host name, host name is omitted, the default port: 80, index.html is a file. URL encoding is not required.
标签: inter process communication, socket programming, java network programming, programming network, target host, post office protocol, resolution protocol, number ip, transmission control protocol, session layer, network transport, computer ip, protocol transport, application layer protocols, host ip address, logical address, osi seven layer model, protocol pop3, transport layer protocols, programming instructions
分类: Java
时间: 2011-01-02


  1. Java Network Programming "shorthand"

    1. What is the TCP / IP protocols? 2. TCP / IP transport protocol which of two kinds, each What are the charac ...
  2. Java network programming sperm solution (01)

    1 OSI Reference Model 1.1 ISO International Organization for Standardization (International Organization for S ...
  3. Analysis of problems in JAVA Network Programming ()

    Said network programming refers to Socket programming, the first listing what language to use JAVA programs So ...
  4. Basic input output IO Java Network Programming Review Minutes

    IO / O → File Class The only information on behalf of the class itself, the disk file (not file content) File ...
  5. Socket-based low-level Java Network Programming

    1, what is the socket? The so-called socket often called the "socket" used to describe the IP addres ...
  6. Java Network Programming Mastering (31): non-blocking I / O Introduction

    In network applications, in general, you can use synchronous I / O (block I / O) and non-blocking I / O data c ...
  7. Reprinted java network programming note points

    1. Network program is running in the common exceptions and handling The first one exception is ...
  8. JAVA Network Programming Socket FAQ [long special topic]

    1. Network program is running in the common exceptions and handling The first one exception is ...
  9. Java network programming non-blocking I / O

    For the CPU faster than the network situation, the traditional solution is to buffer and Java multithreading. ...
  10. Java Network Programming (11): get network interface to use the letter NetworkInterface class

    Starting from JDK1.4, Java provides a NetworkInterface class. This class can get the machine all of the physic ...
  11. Java Network Programming Mastering (22): Implementing HTTP simulator

    In discussing the specific HTTP protocol request and response header fields, let us first use of previously le ...
  12. java network programming to learn --- SOCKET

    Today, learn how to simply use SOCKTE programming. Wanted to see how to use socket and communicate with each o ...
  13. java network programming under the domain name for ip address, URL

    Domain Name, the domain can be converted to ip address InetAddress can also use the getAddress () to get the I ...
  14. Java Network Programming - Building Secure Socket with SSL

    SSL (Secure Sockets Layer) is the Netscape Corporation developed in 1994, initially for the WEB browser, the b ...
  15. Java Network Programming Mastering (33): non-blocking I / O buffer (Buffer)

    If the synchronous I / O mode data transmission compared the data transmission of sporadic way (here is sporad ...
  16. Java Network Programming
  17. Java Network Programming Review

    URL Use url = new URL(""); HttpURLConnection httpUrl = (HttpURLConnection) url . ...
  18. Java Network Programming fine solution - Sun Weiqin

    Length 5.
  19. Java Network Programming Mastering (19): socket (Socket) exception

    In the Socket class has many methods used in the statement throws throws some exceptions that are subclasses o ...