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 CustomerThe 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. |