##DatagramSocket |
() Construct a datagram socket and bind it to any available port on localhost.
## void |
close()
Close this datagram socket.
|
##void
|
##send (DatagramPacket p)
Send datagram packets from this socket.
Parameters:
p - DatagramPacket to be sent.
|
|
DatagramPacket (byte[] buf, int length, InetAddress address, int port)
Construct a datagram packet to send a packet of length length to the specified port number on the specified host.
Parameters:
buf - package data.
length - Packet length.
address - Destination address.
port - Destination port number.
|
#TCP protocol
- Client_Class Socket
This class implements client sockets (it can also be called "sockets"). A socket is the endpoint for communication between two machines.
- Construction method
- The data sent is sent based on the IO stream
- The data sent has no size limit
- The three-way handshake mechanism is used to ensure Data integrity
- Because of the surface connection, the speed is slow
- TCP protocol is Characteristics of the TCP protocol
- Characteristics of the TCP protocol
# #####
|
#Socket(InetAddress address, int port)
Creates a stream socket and connects it to the specified port number of the specified IP address.
Parameters:
address - IP address.
port - Port number.
|
## InputStream
|
##getInputStream ()
Returns the input stream for this socket.
|
##OutputStream
##getOutputStream |
()
Returns the output stream of this socket.
-
Server_Class ServerSocket
This class implements the server socket. The server socket waits for requests to come in over the network. It performs some action based on the request and may then return the results to the requester.
|
#ServerSocket(int port)
Create a server socket bound to a specific port.
Parameters:
port - port number; or 0, which means use any free port.
|
## Socket
|
##accept ()
Listens for and accepts connections to this socket.
Question:
Why does ServerSocket not have a method corresponding to getOutputStream?
Because the server is connected to multiple clients, in order to prevent confusion, the getOutputStream and getInputStream operations are performed by establishing a socket with each client
|
|
|