What is the difference and connection between the client and the server socket?

Source: Internet
Author: User

1. SERVER: Listener
2. Client: Connection

The socket itself is the same, the client is the request, the server is the response, and the stream can be transmitted between them.

One socket: client request

One socket: Server Processing

A connection is a pair of sockets.

Contact:
The socket is equivalent to the stream buffer, and all data in the stream is obtained through their respective sockets. The two-End Socket communicates through a fixed "telephone line", that is, the client selects which server and which port to establish a connection; as the server, only listens to the corresponding port. Here, the client is active.
After the connection is established, both ends can send messages and receive messages through sockets. Both ends of the socket will constantly refresh the content in the socket.

Differences:
After the communication is completed, the server thread closes the socket connection.

The difference is that before communication

The server end is connected to a client at a certain interface to listen to the client connection.End connection
Customer
The IP address and port used to connect to the server,
When the two parties connect, they can communicate with each other. There is no difference between the two parties.
.

The two sockets form an interconnected socket interface, and establish a communication channel between the client and the server.
Inputstream in = new inputstream (S. getinputstream ());
Outputstream out = new outputstream (S. getoutputstream ());

You can create an input/output stream at both ends for communication.

The Socket socket created by the client communicates with the Socket socket returned by the accept () method on the server, while the socket created by serversocket is only used to listen to the connection requests of the client without communication.

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.