Java-network programming URL and urlconnection

Source: Internet
Author: User

URL (Uniform Resource loactor abbreviation of Uniform Resource Locator) through the constructor can get URL object url = new URL ("http://www.cnblogs.com ");

Basic URL Method

Getportocal (): Get the transfer protocol

Gethost (): Get the Host Name

Getport (): Get the port number

GetFile (): Get the resource file name

Urlconnection is an abstract class. It is a dynamic connection to the data source specified by the URL. It provides more powerful server interaction functions than the URL, data can be submitted to the server using post/get and other HTTP request methods.

Getcontenttype (): Get the Document Type

Getcontentlength (): Object Length

Getdate (): the time when the file was created.

Getlastmodified (): Last object modification time

Getinputstream (): input stream

TCP/IP server and client socket

Socket sockets are divided into server sockets and client sockets.

Client socket specifies the server address and port number to be connected socket socekt = new socket (string host; int port)/Socket socket = new socket (inetaddress add, int port)

Server socket serversocket Ss = new serversocket (INT port); the server socket runs on a specific port of the server and listens to TCP requests on this port. After the client requests a connection and passes verification, the server can interact with the client.

Inetaddress is an IP address class. You can obtain the inetaddress object getlocalhost (), getallbyname (string IP/host), and getbyname (string IP/host) in three ways ); getbyaddress (byte [] ADDR)

Getbyaddress (string host, byte [] ADDR ).

Obtain the Host Name: getcanonicalhostname (); The creation method of inetaddress (string local/string IP/string host) determines whether domain name resolution is required. The first one does not need domain name resolution, third, uncertainty

Obtain the host alias: gethostname (); The creation method of inetaddress (string local/string IP/string host) determines whether domain name resolution is required, both the first and third do not use domain name resolution.

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.