Refer to "Linux High Performance Server Programming"When dealing with multiple connections under Linux, it is inefficient to use only multithreading and raw socket functionsThen there is the SELELCT poll Epoll and other IO multiplexing functions.Epoll IO multiplexing with optimal performance is discussed hereThe user will need to focus on the socket connection us
","Ipv6-frag","IDRP","RSVP","GRE","ESP","Ah","Skip","IPV6-ICMP","IPV6-NONXT","Ipv6-opts","RSPF","VMTP","EIGRP","OSPF","ax.25","Ipip","Etherip","EnCap","PIM","Ipcomp","VRRP","L2TP","ISIS","SCTP","FC", NULL}; Setprotoent (1);/ * Do not close the file when using function Getprotobyname/etc/protocols*/ while(Protocol_name[i]!=null) {/ * Not to end of array protocol_name * / structProtoent *pt = Getprotobyname ((Const Char*) protocol_name[i][0]);/ * Query protocol * / if(PT) {/ * Su
the cause of sigpipe signal in TCP/IP protocol 1 Suppose that the client socket socket close () will send a byte segment to the server fin; 2 The server receives fin, but does not call close () because the socket has a buffer, so the server can still send data to the client. 3. If the server sends data to the client in this state, it will cause the tcp/IP protocol to reset the RST segment, causing the server to send a sigpipe signal to the current process, and the default action of Sigpipe sig
follows:
/************************************************************************* > File name:server.c > Author:song Lee ************************************************************************/#include
The client-side code is as follows:
/************************************************************************* > File name:client.c > Author:song Lee ************************************************************************/#include
Readers can refer to the previous:
, consider thread synchronization.3. Service when client thread exits, exit processing (exit value, works thread is in detached state)4. System load, as the number of linked customers increases, causing other threads to be unable to stage the CPU .server code [ In actual development, pay special attention to function call return value judgment ] #include multi-threaded and multi- process by Model CPU debugging in Linux, so the use of multi-threaded a
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 source.
Sometimes we need to control
Preface
This section describes how to use basic Linux/Unix functions and poll calls to compile a complete server and client example that can be run on Linux (UBUNTU) and Unix (FreeBSD, the functions of the client and server are as follows:
The client reads a row from the standard input and sends it to the server.
The server reads a row from the network and
Addressvariable part of IP datagram header :The variable part of the IP capital is an optional field. Option fields are used to support troubleshooting, measurement, and security measures, and are rich in content. This field is variable in length, ranging from 1 bytes to 40 bytes, depending on the item selected.Some options require only 1 bytes, and it includes only 1-byte option codes. However, there are several options that require multiple bytes, which are stitched together, with no delimite
, 0x0012ff40, 0x0012ff41, 0x0012ff42, 0x0012ff43 the values of the four units are: 00, 40, 32, 14, that is, the high portion of the original number 0x403214 stored in the low address, the lower part is stored in the high address. Thus, if a number is stored in small-tailed order, the high-status byte of the number after the HTONL function call is completely reversed to become a new number. This new number is actually stored in small-tailed order inside the machine, but it is equivalent to a larg
Three. Deep analysis of network subsystemThe user program sends this network packet over the networkPassSciProtocol-Independent InterfacesProtocol stack the implementation of UDP chooses the routeThe implementation of IP will establish this neighbor subsystem and establish the neighbor informationDevice-Independent interfacesDrivenfunction call relationship (corresponds to above)Socket_file_opsDo_sock_write
; } } if(i = =maxsocket) { //the socket pool is full and the client connection is closedClose_socket (Client_st); } } //processing the client socket for(i =0; i ) { if(Client[i] = =-1) { //Invalid socket Direct exit Continue; } //determine if this socket has an event if(Fd_isset (client[i), Allset)) { //Receiving Messages if(Soc
To thoroughly understand poll or understand the following code, please refer to the "Linux network programming--i/o multiplexing poll function"Code:#include Operation Result:Source Download:Linux Network Programming--tcp Concurrent Server (poll implementation)
I. Overview of TCP concurrent Servers
A good server, typically a concurrent server (a request that can respond to multiple clients at the same time). Concurrent server design techniques generally include: multi-process servers, multi-threaded servers,I/O multiplexing servers, etc.
second, multi-process concurrent server
There are many applications in the Linux environment, the most important of which is the
Linux Network Programming-general Linux technology-Linux technology and application information. For more information, see the following section. /**
* A sample server
*/
# Include
# Include
# Include
# Include
# Include
# Include
#
In linux, is network programming non-blocking? Is the server unable to accept data? -- Linux general technology-Linux technology and application information. For details, refer to the following section. /* This is the client code */
# Include
# Include
# Include
postponed by a few seconds.4. TCP will keep its header and data checksum. This is an end-to-end checksum to detect any changes in data during transmission. If the verification and error of the received segment are received, TCP discards the segment and does not confirm it (resulting in timeout retransmission)5. TCP is carried by IP datagram, and the arrival of IP datagram may be out of order, so the arrival of TCP packet segments may also be out of order. TCP sorts the received data again.6. Du
I have developed a common data transmission module in my work, and the followers of C ++ are growing fast. I will share some experiences in this article.
1. Basic Concepts
Create three handshakes for TCP connections and disconnect four handshakes for TCP connections.
2. troubleshooting tools:
1). netstat-anp | grep your's Port:
This command is used to check the status of your port in Linux. It can be used to check whether the connection is established
);/ * The first converted value of the 16-bit value * /printf"\t2 Times:"); Showvalue (v16_turn2.byte, BITS16);/ * The value after the second conversion of the 16-bit value * /printf"host to network byte order change:\n"); printf"\torig:\t"); Showvalue (V32_orig.byte, BITS32);/ * Raw values for 32-bit values * /printf"\t1 Times:"); Showvalue (v32_turn1.byte, BITS32);/ * The first converted value of the 32-bit value * /printf"\t2 Times:"); Showvalue (v
delivery(4) TCP will automatically adjust the adaptation rate (sliding window technology) based on the network bandwidth, and if the receiver receives less pressure, it will slowly increase the transmit rate, and the sender will slow down the sending speed when the receiver pressure is high.(5) The sender will give each division message number, the receiver will check the number, once the order error will be re-transmitted.Third, the TCP protocol lea
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