Java socket programming (1) (1)
Using Java and development of network software is very convenient and powerful, Java's strength lies in his unique to this set of powerful network for the API, API is a series of classes and interfaces, and are located in the package java.net javax. in the net. In this article we will introduce socket (Socket) expense read, and illustrates how to use Network API manipulation of the socket, after the completion of this article, you can prepare low-end network communication software.
What is the socket (Socket)?
Network API is typical for TCP / IP-based network Java programs and other communications procedures, Socket Network API rely on the communication. Socket can be regarded as the two procedures in a communications link endpoint, a procedure will be a message into the Socket, the Socket this information will be sent to another Socket, to transmit this information to other procedures. Figure 1

We have to take a look at Figure 1, Host A program on the A Socket will write in a message, the content of the Socket Host A visit to the network management software, and this information through the Host A network interface card sent to Host B , Host B network interface card to receive this information, transmitted to Host B network management software, network management software, this information will be stored in the Socket Host B, then B can be in the process of reading this information Socket .
Assuming that the network plans to add a third host Host C, Host A how that information was transmitted to the correct Host B and not transferred to Host C in? Based on the TCP / IP network hosts were each given a unique IP address, IP address is a 32-bit unsigned integer, in the absence of changes in a binary, it is usually a decimal point separated, such as: 198.163.227.6, As seen by the IP address of four parts, each part of the range is 0-255, said that eight addresses.
It is worth noting that IP addresses are 32-bit addresses, it is IP protocol version 4 (Ipv4) regulations, due to the current IPv4 addresses is almost exhausted, so IPv6 address is gradually replace Ipv4 address, Ipv6 address is not 128 unsigned integers.
The second assumption was joined procedures Figure 1 Network Host B, then the Host A How can it be by the information coming from the correct procedures B transmission rather than pass new procedures? This is because each one based on the TCP / IP network communications procedures have been given only port and the port, the port is a message to the buffer zone, for the retention of Socket input / output information, is a 16-port, bit unsigned integer, the scope of 0-65535, to distinguish between a host of procedures (like ports, in the room housing), less than 256 short slogan reserved for standard applications, such as ports, pop3 is 110, Each socket is a portfolio into IP addresses, ports, ports, the overall formation of this distinction can be a socket t, as we turn to two socket: Socket and self - addressable data socket.
Tags: java programming ideas, java programming language, java socket, Socket






