Java Socket Programming

Source: Internet
Author: User

Tag: Test row represents network traffic for throw get static str

Brief introduction:

PORT: 1

1. Used to differentiate different applications.

2. Port number range 0~65535, 0~1023 is reserved for the system.

The 3.IP address and port number make up the socket. Sockets are the endpoints of two-way communication links between programs running on the network, and are the basis for TCP and UDP.

4. Common port number HTTP ftp:21 telnet 23

Network support in Java:

For the different levels of network communication, divided into four categories

1.InetAddress, which represents the hardware class on the network (identifies IP address related information)

2.URL: Network Resource location

3.Sockets: For TCP

4.Datagram: For UDP

Package com. inetaddress;

Import java.net.InetAddress;
Import java.net.UnknownHostException;
Import Java.util.Arrays;

public class Test1 {

public static void Main (string[] args) throws unknownhostexception{
InetAddress address = Inetaddress.getlocalhost ();
SYSTEM.OUT.PRINTLN ("Computer name:" + address.gethostname ());
SYSTEM.OUT.PRINTLN ("Address of the computer:" + address.gethostaddress ());
byte[] bytes = address.getaddress ();//Get IP in byte array form
System.out.println (arrays.tostring (bytes));
SYSTEM.OUT.PRINTLN (address);
InetAddress address2 = inetaddress.getbyaddress (bytes);
InetAddress address2 = Inetaddress.getbyname ("");
System.out.println (Address2.gethostaddress ());
}
}

Java Socket Programming

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.