Java network programming (TCP explanation)

Network programming details - TCP

First, the characteristics of TCP protocol are connection oriented protocol (if there is a sender, there must be a receiver)

Establish a connection through a triple connection handshake

Disconnect with four handshakes

Data transmission based on Io streaming

There is no limit to the size of transmitted data

Slow but reliable

Second, introduce the common construction methods of two classes of socket related to TCP protocol (a socket object represents a client object)

   Socket(String host,int port)

When you remember, you can use this memory method: remember that the socket is a client object. The parameters are like that since the socket object is a client object, it needs to connect to the server, so what does it need? The connection server must need the IP and address of the server to connect.

III. introduction to common methods

OutputStream getoutputstream() get byte output stream() InputStream getinputstream() get byte input stream() void shutdownoutputstream() close output stream() void close() close resource int getport() get server port InetAddress getinetaddress()

Fourth, obtain the IP address object of the server

Introduction to common construction methods of ServerSocket (an object of this type represents a server object)

   ServerSocket(int port)

The port parameter is the port number of the server

Introduction to common methods

Socket accept() waits for the client to connect, obtains a client object, and getinteaddress() obtains the IP object of the connected client

 . Put the customer login information in user Properties file, persistent information base

  3. Server side code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>