Java TCP/IP socket programming Chapter 4 Advanced

Source: Internet
Author: User
Note: This note is suitable for summary and review by people who have read this book, not suitable for entry-level learning Chapter 4 advanced 4.1 multi-task processing iterative server means that the server can only process one client parallel server at a time. It means that the server can process multiple clients simultaneously to Implement Parallel Server in three ways, one customer thread 2, thread pool 3, built-in tool * Logger Applications 4.2 blocking and timeout socket I/O cause timeout in the following situations
  • Read ()
  • Receive ()
  • Write ()
  • Serversocket accept () method
  • Socket () constructor
Three methods can be used to block read (), receive (), and accept (). You can use setsotimeout () to set the maximum blocking time, if this method has not been returned within the specified time, two constructor Methods blocking the write () method and socket () method that cannot be solved will be thrown, the latter needs to block the connection until the write () method is complete. Cause: if a large amount of data is written, because the data is written to a local cache implemented by TCP, when the cache is full, the write () method blocks the wait until the data in the cache is successfully sent to the other end of the connection. Therefore, write () the blocking time of the method also depends on the receiver's application. Java does not have any method to interrupt the blocking of the write () method. More than 4.3 recipients
  • One-to-one communication method: thin
  • One-to-multiple communication methods: Broadcast and Multicast (only UDP sockets allow broadcast and Multicast)
4.3.1 broadcast address
  • IPv6 does not explicitly provide broadcast addresses, but there is a special full-node multicast address within the local connection range, ff02: 1 (you need to further query the materials for learning)
  • IPv4 local broadcast address: 255.255.255.255.255
Broadcast range
  • The local broadcast information will never be forwarded by the router. The sent information can only be received by other hosts on the same Ethernet.
  • IPv4 also provides a targeted broadcast address that can broadcast to all hosts in the specified network. However, many vrouters do not support
  • There is no broadcast address for sending messages to all hosts in the network range, because many data packet copies are forwarded on the same vro, which consumes all network bandwidth.
4.3.2 The multicast IP protocol designer allocates a certain range of address spaces for multicast in IPv4. The multicast address ranges from 224.0.0.0 to 249.255.255.255ipv6. The multicast address is any address starting with ff. the program communicates through the muticastsocket instance (it is a subclass of the initramsocket) principle: The multicast server sends messages to a multicast address (also known as a group), while multicast clients set the group they are interested in, then, receive information from that group. A multicast client can be interested in multiple groups. Multicast and broadcast relationship broadcast range can only be within a local Broadcast Network Multicast Communication may include a receiver of any location in the network 4.4 control default behavior 4.4.1 Keep-Alive4.4.2 send and accept buffer size 4.4.3 timeout 4.4.4 address reuse 4.4.5 eliminate buffer delay 4.4.6 when emergency data 4.4.7 is closed, stay at 4.4.8 broadcast license 4.4.9 communication level 4.4.10 based on performance protocol selection (some of the above 10 points are basically not used or rarely used, 4.5 close resources this section mainly describes the use of the socket close () method and the use of the shutdowninput () method or shutdownoutput () method () methods are different. For example, when a client sends a message to the server, the server stops receiving information when the client closes the socket. However, if the server receives the information, it processes the information and sends it back to the client, at this time, because the client closes the socket and cannot receive messages sent from the server, when the client ends sending messages to the server, select shudownoutput () instead of closing the socket, the server can get the end mark of the stream or send a message back to the client.
Related Article

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.