1. Use the Read function to return the story of length 0: Closes the connection to the end, and the service side calls the close function.//INTRO/DAYTIMETCPCLI.C while((n = Read (SOCKFD, Recvline, MAXLINE)) >0) {Recvline[n]=0; if(Fputs (recvline, stdout) = =EOF) Err_sys ("fputs Error");}if(N 0) Err_sys ("Read Error");/*-------------------------------------------------------------*///intro/daytimetcpsrv.c for ( ; ; ) {CONNFD= Accept (LISTENFD, (SA *) NULL, and NULL); Ticks=Time (NULL); snprintf (
In the commissioning of CS, the S-end loop, the C-terminal loop, the S-end after an unexpected crash, the C-terminal automatic exit, terminal hint Sigpipe cause C end exit. Man 7 signal:Sigpipe broken pipe:write to pipe with no readersSigpipe occurs when: Write a pipe that is not read, the default action is to terminate the program. Man 2 write:Epipe is is closed. This happens the writing process would also receive a sig- PIPE signal. return is if th
(3) byte orderThe highest significant bit is stored at the lowest memory address, and the least significant bit is stored at the highest memory address.The highest significant bit is stored at the highest memory address, and the least significant bit is stored at the lowest memory address.Save 0x12345678-----------------> The direction of memory address growth12 34 56 78 big endian byte order78 56 34 12 small-endian byte-orderDifferent hosts have different byte-order, such as x86 is the small-en
bind the contact method. The client sends a (SENDTO) message to the server through this contact, because this contact is bound to the server's socket port, so the server must be able to receive (RECVFROM) messages, at the same time through the outgoing parameters of Recvfrom to obtain the client's contact information, This allows messages to be sent to the client through the client's contact. That is, UTP communication is based on the contact method (IP and port number). is an unreliable means
Linux Network Programming-TCP status change
As shown in the figure above, TCP has a status of 11. data sent and received by TCP includes ACK, FIN, Syn, and RST. for a client that has not called Connect and a server that has not called listen, they are all in the closed state. ack is the response information. Any end (client or server), after receiving data
For Linux network programming, we all know that UDP is used to send data packets, not connection-oriented protocols, that is, it only sends data packets to the link layer. As for whether it can reach the destination IP address and port, there is no other way to do it. In addition, you only need to specify the port and IP address you want to send in the sendto fun
Linux Network Programming-file attributes fcntl Function
/* Use the fcntl control file operator */# include
# Include
# Include
Int main (void) {int flags =-1; int accmode =-1;/* Get the status of the standard input */flags = fcntl (0, F_GETFL, 0 ); if (flags
Example 1: Use the int fcntl (int fd, int cmd) function. The returne
following:
Copy codeThe code is as follows:
Void
Sig_chld (int signo)
{
Pid_t pid;
Int stat;
While (pid = waitpid (-1, stat, WNOHANG)> 0)
Printf ("child % d terminated \ n", pid );
Return;
}
So far, we have solved three possible
Common socket typesProvide connection-oriented, reliable transport services, data error-free, no duplication of transmission,and received in the order in which they were sent.provides no connection service. No error-free guarantees are provided, data may be lost or duplicated, and receive order confusion."Linux network Programming" common socket types
Write one of the simplest TCP communication clients. The code is as follows:#include The simplest TCP communication client for Linux network programming
The socket descriptor and the generic file descriptor do not differ in form, so how can I tell if a file descriptor is a socket descriptor? Here we will simply customize a function Issockettype for socket descriptor determination.#include #include #include #include #include #include intIssockettype (intFD) {structStat St;intErr = Fstat (fd, st);//Get the status of the file if(Err 0) {return-1; }if((St.st_mode s_ifmt) = = S_ifsock) {//Use system macros to compare whether a socket descriptor
continue to wait before returning to the Beacon. What are the advantages of it, it is clear that 100 people can complete the things you have done, and a number of takeout may be at the same time, the road has gone a lot.As for the shortcomings, of course, every time you have to take the 100 receiving point all go once (weight loss is not so spelled)
Find the epoll function, it will give you a mobile phone, delivery master takeout delivery can give you a call. With the mobile phone, all thi
" Daoyan" 0 two values, used to vote, it should be noted that the database is only for the purpose of polling after the data to be updated on the return page, so, if you want to simple. I think it's enough to use the file. Not enough of this example is because the data is very simple, but if there are very many complex operations, or to build a database is more convenient!Step Three: WriteCGIProgram This is the most critical step. This step is completed when the user votes. After the return of
Files obj = $ (patsubst./%.C,./%.O, $ (src)) #将所有. c files are assigned to. o# variable assignments, parameters specified at compile time-lpthread the specified thread Need library, #-std=gnu99 specify C99 standard compile-G to add debug information for GDB debugging use-wall more tips cc = gcc-g-wall-std=gnu99-lpthread# Specify target genetic server Clientall:serveR client# Specify genetic server target dependencies and commands SERVER:WARP.O server.o$ (CC) $^-o [email protected] #指定生成client目标
then read from memory:Next, do a fault-tolerant processing:In fact, the mapping failure has a special macro definition, which can be learned from the man help:So, instead of the-1 program will be more readable:Compile run:What is this for? Or from the man help to find the answer:So the cause of the problem is found, then modify the open mode to either:Compile and run again:There is no successful write, you need to write a read program to verify:Compile run:You can actually use the shell command
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.