Java.net.ServerSocket and Java.net.Socket

Source: Internet
Author: User

Personal blog Address: http://www.cnblogs.com/wdfwolf3/

Java.net.ServerSocket

1. Constructors

A.serversocket ()

Create a non-connected server socket.

B.serversocket (int port)

Binding to Port ports

C.serversocket (int port, int backlog)

Backlog indicates the maximum length of queue waiting to be connected

D.serversocket (int port, int backlog, inetaddress bindaddr)

The parameter bindaddr represents the local IP address to bind.

2. Main methods

A. Socket accept ()

The listening port establishes a connection to the socket that sends the request.

B. Void bind (socketaddress endpoint, int backlog)

For the initial server socket-bound port without a bound port, endpoint is the port to bind, and the backlog can be omitted, functionally in the same constructor.

c. void Close ()

Close the server socket.

d. int Getlocalport (); SocketAddress getlocalsocketaddress (); Serversocketchannel Getchannel ();

These few names can be used to know.

Java.net.Socket

1. Constructors

A. Socket ()

Create a non-connected socket.

B.socket (inetaddress address, int port)

Creates a new socket that connects to the specified IP address and port.

C.socket (String host, int port)

Creates a new socket that connects to the specified host name and port.

2. Main methods

A. void bind (SocketAddress bindpoint)

B. void close (); inetaddress getlocaladdress (); int getlocalport (); int Getport ()

As the name implies, ditto as well to understand

C. InputStream getInputStream (); OutputStream Getoutputstream ()

Returns the input and output streams for this socket.

Java.net.ServerSocket and Java.net.Socket

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.