The channeloption of Netty

Source: Internet
Author: User

I. Overview

Recently wrote a distributed service framework, intended to use the Netty framework for the underlying network communication, about Netty learning can refer to the following information:

Http://blog.csdn.net/column/details/enjoynetty.html

Li Linfeng's "authoritative Guide to Netty"

Second, details

When using Netty as the underlying network communication on the parameters of the channeloption I have been unclear, so to see the Linux network programming, found that the various properties of channeloption in the socket options have corresponding

The following is a simple summary of the meaning of channeloption and the use of the scene

1, Channeloption.so_backlog

Channeloption.so_backlog corresponds to the backlog parameter in the TCP/IP protocol listen function, the function listen (int socketfd,int backlog) is used to initialize the server-side connection queue,

Server-side processing client connection requests are processed sequentially, so only one client connection can be processed at the same time, when multiple clients come, the server will not be able to handle the client connection requests in the queue waiting for processing, the backlog parameter specifies the size of the queue

2, Channeloption.so_reuseaddr

The channeoption.so_reuseaddr corresponds to SO_REUSEADDR in the socket option, which means that local addresses and ports are allowed to be reused.

For example, a server process consumes TCP 80 port for listening, at this time to listen to the port again will return an error, use this parameter can solve the problem, this parameter allows to share the port, which is more commonly used in the server program,

For example, a process is not normal exit, the port may be occupied by the program for a period of time to allow other processes to use, and after the program is dead, the kernel needs a certain amount of time to release the port, do not set SO_REUSEADDR

The port will not be used properly.

3, Channeloption.so_keepalive

The channeloption.so_keepalive parameter corresponds to so_keepalive in the socket option, which is used to set up a TCP connection, and when set, the connection tests the status of the link, which is used for potentially long periods of time without data exchange.

Connection. When this option is set, TCP automatically sends an active probe data packet If there is no data communication within two hours.

4, Channeloption.so_sndbuf and Channeloption.so_rcvbuf

The CHANNELOPTION.SO_SNDBUF parameter corresponds to the SO_SNDBUF,CHANNELOPTION.SO_RCVBUF parameter in the socket option that corresponds to the SO_RCVBUF in the socket option that is used to manipulate the receive buffer and the send buffer

, the receive buffer is used to hold the data received within the network Protocol station until the application reads successfully, and the send buffer is used to hold the sent data until it is sent successfully.

5, Channeloption.so_linger

The Channeloption.so_linger parameter corresponds to the socket option in the So_linger,linux kernel by default, when the user calls the close () method, the function returns and, if possible, sends the data as much as it is not necessarily guaranteed

The remaining data will occur, causing uncertainty in the data, using SO_LINGER to block the call time of close () until the data is completely sent

6, Channeloption.tcp_nodelay

The Channeloption.tcp_nodelay parameter corresponds to the tcp_nodelay in the socket option, and the use of this parameter is related to the Nagle algorithm

The Nagle algorithm is to assemble a small packet into a larger frame and then send it instead of the input once, so when the packet is insufficient, it waits for the other data to be assembled into a large packet to send, although the method effectively improves the network's effective

Load, but caused the delay, and the role of this parameter is to prohibit the use of the Nagle algorithm, for small data instant transmission, Tcp_nodelay is corresponding to the tcp_cork, the option is to wait until the maximum amount of data sent, one-time send

data, suitable for file transfer.

Iii. Summary

Recently use Netty feel Netty really is very powerful, also very useful, recommend everybody to study.

The channeloption of Netty

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.