SetSockOpt Method
[CPP]View Plain copy print? #include
intSetSockOpt (
intSocket
intLevel
intOption_name,
Const
void*option_value,
size_tOption_len);
The first parameter socket is a socket descriptor.
The second parameter level is the levels of the
1. getsockopt and setsockopt Functions
These two functions are only used for sockets:
# Include int getsockopt (int sockfd, int level, int optname, void * optval, socklen_t * optlen); int setsockopt (int sockfd, int level, int optname, const void
Article title: Linux network programming-8. socket options. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open
###########################################################System calls related to socket options:###########################################################Set the value in the cell pointed to by optval to the optname option:int setsockopt(int
Set SO_RECVBUF and SO_SENDBUF socket options, sorecvbuf
Control socket behavior (such as modifying the buffer size ).
Int getsockopt (int sockfd, int level, int optname, void * optval, socklen_t * optlen );
Int setsockopt (int sockfd, int level, int
Socket options are typically set through the following functions: GetSockOpt and SETSOCKOPT functions; fcntl functions; IOCTL functions
#include /* See NOTES */
#include
int getsockopt ( int sockfd int
Linux Network Programming socket options so_linger, so_reuseaddr
In Linux network programming, there are many socket options. Several of the most important options are: so_linger (only applicable to TCP and sctp), so_reuseaddr.
So_linger
By
In some cases, we need to further control the socket behavior and attributes, such as modifying the buffer size and viewing the socket status. Therefore, we need to set/obtain the socket options.
1. Obtain socket optionsint getsockopt(SOCKET s,int
Linux program design-socket options (Chapter 1), linux Program DesignNow we can improve the customer program so that it can be connected to any host with a name. This time, instead of connecting to the sample server, it is connected to a standard
The socket mechanism provides two socket option interfaces to control the behavior of sockets. An interface is used to set options, and another interface is used to allow us to request the status of the option. We can get and set three kinds of
/* Set the socket option to periodically detect the connectivity heartbeat packet and Xinbo. It is mainly used for persistent connections. * Parameter: socket, 1 or 0 enabled, first interval, two intervals, number of disconnections */void
Erlang R17 introduces the new socket option {active, N}. Together with {active, once}, it provides traffic control for the application layer. Why does the option {active, once} effectively suppress a large number of socket messages?
We know that
socket.setsockopt(level, optname, value)↑↑↑→[so_keepalive,↑so_linger,↑so_rcvbuf,↑so_sndbuf,↑so_rcvlowat, So_sndlowat,↑so_rcvtimeo, So_sndtimeo,↑SO_REUSEADDR]According to the difference of the level value of the parameter optionSocket options are
Now you can improve the client program so that it can connect to any host that has a name, this time not connecting to the sample server, but connecting to a standard service, so that you can demonstrate the port number extraction operationThe.Most
From http://blog.csdn.net/feiyinzilgd/article/details/5894300In Linux network programming, there are many options for sockets. Several of the more important options are: So_linger (only for TCP,SCTP), so_reuseaddr.
So_linger
By default,
now it is possible to improve the client program so that it can connect to any host with no name, this time instead of connecting to the Demo sample server, but connecting to a standard service so that it can demonstrate the port number extraction
Sometimes we need to control the behavior of sockets (such as changing the size of the buffer), and we're going to learn the socket options.
int getsockopt (int sockfd,int level,int optname,void *optval,socklen_t *optlen)
int setsockopt (int
From: http://lydnkj.bokee.com/viewdiary.10417372.html
Getsockopt and setsockopt
Obtain the set Interface Options:
Code:
Int getsockopt (INT sockfd, int level, int optname, void * optval, socklen_t * opteln) sets the set of Interface Options:Int
1.Closesocket (usually does not close immediately and goes through the time_wait process) and wants to continue to reuse the socket:Bool breuseaddr = true;Setsockopt(S, sol_socket, so_reuseaddr, (const char *) & breuseaddr, sizeof (bool ));
2.If you
A tcp disconnection exception occurs when a sudden power failure or network cable disconnection occurs. If no data transmission or communication is processed by both parties, the connection is disconnected.
In general, in order to prevent socket
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.