, BITS16);/ * 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:"); Show
Non-blocking I/O includes non-blocking input operations, non-blocking output operations, non-blocking receiving foreign connections, non-blocking initiating outgoing connections. The functions included are: Read, Readv, recv, Recvfrom, Recvmsg, write, Writev, send, SendTo, sendmsg, accept.
There are three general ways to set the socket to non-blocking mode:
(1) When creating a socket, specify that the socket is asynchronous and set the SOCK_NONBLOCK flag in the parameter of type.
int socket (in
(SOCKFD); theEVENTS[I].DATA.FD =-1; the } theEV.DATA.FD=SOCKFD;//set file descriptors for write operations -Ev.events=epollout| Epollet;//set up write events for the injection test inEpoll_ctl (Epfd,,sockfd,ev);//Modify the event to be handled on SOCKFD as Epollout the } the Else if(events[i].eventsepollout) About { theSOCKFD =EVENTS[I].DATA.FD; the Write (sockfd, line, n); theEV.DATA.FD=SOCKFD;//set the file descriptor for the read operation +ev.events=epollin| Epollet;//to set the re
Network Programming in Linux-raw socket (1)
Http://soft.zdnet.com.cn/software_zone/2007/1020/568223.shtml
We have learned two sockets (sock_stream, sock_dragm) in the network program. In this chapter, we will learn another socket-the original socket (sock_raw ). The original socket can be used to compile functions tha
Linux Kernel network protocol stack------SK_BUFF structure and fully interpreted (2.6.16) See also "heap sort"Xyrouter is a library that resolves Uiviewcontroller jump dependencies through URL routing.Select () functions and Fd_zero, Fd_set, FD_CLR, Fd_isset Programmer boyfriend Product canvas (unfinished) Ping an architect mobile app architecture design very good iOS KVO use and lightweight packageXyquickT
When doing network service, it is necessary to write concurrent service-side programs. The stability of the front-end client application is partly dependent on the client itself, and more depends on whether the server is fast enough and stable enough.The common Linux concurrent Server model;
Multi-Process Concurrent server
Multi-threaded Concurrent server
Select multi-channel I/O transf
()); Echo (CLIENTFD); Close (CLIENTFD); return NULL;}Operation Result:The problem with this code is that after clientfd the incoming thread, the ARG pointer does not receive a value, meaning it is in an inaccessible place (GDB displays a value of 0x00) and the solution is baffled.(The principle is very simple, the problems encountered first recorded, if someone knows where the wrong hope can correct it out ...) Environment Ubuntu 64 bit, compiler GCC) Copyright NOTICE: This article for
Preface
This section describes how to use basic Linux functions and epoll to compile a complete server and client example. 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 then outputs the row to the client.
The client receives a response from the server and outputs this line
handling (as described in the Fork section).void Error_msg (char *msg) { perror (msg); Exit (0);} int Fork () { pid_t pid; if (PID = fork ()) Execution Result:ClientServerMultithreadingThreads and processes are interlinked in very many ways, modeled on the traditional model of multi-process above. It is not difficult to implement the traditional model of multithreading.is still in the while inside to make simple changes can be. CLIENTFD = (int*) malloc (sizeof (int));
does not have a relationship with the socket descriptor, even if the call to shutdown (FD, SHUT_RDWR) does not close the FD, and eventually close (FD) is required.3, it can be considered that shutdown (FD, SHUT_RD) is an empty operation, because after shutdown can continue to read data from the socket, this may need further confirmation.4, write the socket descriptor after the fin package has been sent raises epipe/sigpipe.5, when more than one socket descriptor points to the same socket object
following:Figure 9 TCP Connection Second handshake instance Why is MSS 1452 instead of 1460?This is due to the use of PPPoE (point-to-point over Ethernet. Enables the Ethernet host to connect to an unwarranted access concentrator via a simple bridging device [3]) dial-up internet access. The Ppop header is 8 bytes, so the MTU of PPPoE is 1492,MSS and 1492-40=1452. So, what is the MSS that transmits data after the TCP connection is established, 1460 or 1452 or 536? My understanding is the defaul
to experience So_linger need to set So_dontlinger, or set l_onoff=0;10. Another less used is in the SDI or dialog program, you can record the socket debug information:(The test of this function has been done before, the mode information can be saved, including the parameters of the socket when it was established, the use ofThe specific protocol, and the code of the error can be recorded)BOOL bdebug=true;SetSockOpt (S,sol_socket,so_debug, (const char*) amp;bdebug,sizeof (BOOL));
The example program described in this paper is a socket network programming based on Linux platform, which realizes the file transfer function. This example is a socket network File transfer program based on the TCP stream protocol implementation. Written in C language. Eventually, you can implement a file transfer pro
(SOCKFD, (struct sockaddr*) client_addr, cliaddr_len);p Thread_ Create (thread_id, NULL, (void *) Client_fun, (void *) CONNFD); Pthread_detach (thread_id); }
because void * is 4 bytes, 4 bytes,
2. The last parameter of the Pthread_create () function above is can I pass an address? Yes, but it can cause unpredictable problems for the server
while (1) {int connfd = accept (sockfd, struct sockaddr*
for the TCP three-way handshake process to be completed.2. Queue with Connection completed
As shown in:
4. Accept Function
Include header file Function: returns the first connection from the completed connection queue. If the completed connection queue is empty, the connection is blocked.Prototype: int accept (INT sockfd, struct sockaddr * ADDR, socklen_t * addrlen );ParametersSockfd: server socketADDR: the socket address of the peer is returned.Addrlen: returns the socket address length of t
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