Discover linux socket programming by example pdf, include the articles, news, trends, analysis and practical advice about linux socket programming by example pdf on alibabacloud.com
illustrations:Take unsigned int value = 0x12345678 as an example, and look at its storage in two byte sequences, we can use unsigned char buf[4] to represent value:Big-endian: Low address holds high , such as:Bottom of stack (high address)---------------BUF[3] (0x78)--LowBUF[2] (0x56)BUF[1] (0x34)Buf[0] (0x12)--high---------------Top of stack (low address)Little-endian: Low address storage , such as:Bottom of stack (high address)---------------BUF[3]
Many people think that using write and sending data using send is the same, and you can actually send data, but one thing to note:The Write function does not guarantee that the sent data can be sent at once, possibly sending only a portion (when the kernel sends a buffer full), which destroys the "atomicity" of the data sent, which is only the process of sending a single packet that is not affected by other send operations. If the middle is interrupted, then the other threads on the same
Data reading and writing are dividedTCP Data read/write, UDP data read/write, general data Read/write1.TCP Data read/writeDefinition: Socket is the connection between user space and kernel space, TCP and UDP are the first layer of the kernel.Explanation: Read and write for files also apply to the socketExample: System call for TCP streaming data1.1ssize_t recv (int sockfd,voidbuf,size_t len,int flags);1.2ssize_t Send (int sockfd,const voidbuf,size_t l
When the client calls the close function, the server's read function reads the data is 0 read to the end of the file notification, indicating that the TCP connection is closed to the endOur reality is to implement the following features:1, the TCP client obtains the input data from the standard input stream to the server, after the server receives the data, does not make any changes, returns the calligraphy to the client, after the client receives the server's data, outputs in the standard outpu
Ethernet Message Format:For detailed instructions, see "MAC Head Message Analysis".IP Message Format:For detailed instructions, see the IP datagram format.UDP Message Format:For detailed instructions, see the format of theUDP datagram.Checksum function:/******************************************************* function: Checksum function parameter: buf: Need to verify the first address of the data Nword: need to verify the data length of half the return value: CHECKSUM * * * * /unsigned Short Chec
1: UDP communication block diagram
The above client can also perform BIND () and connect operations. In the following client code, we implement this. 2: UDP server code
# If 1 # include ". /.. /.. /udp_client/src/iolib. H "/* add your own I/O function library */# define max_line 100 // extern int checkselect (INT handfd, char * rwflag); void my_fun (char * P) {If (P = NULL)/* empty string */return; For (; * P! = '\ 0'; P ++) if (* P> = 'A' * P 3: UDP client code
# Include ". /iolib. H "/* add y
1. Using zip and unzip compression and decompression zip Aa.zip file name (one) zip aa.zip file name 1 file name 2 (compress multiple files) zip-r Aa.zip folder path (Compress entire folder) Zip-t 102002 File.zip Compress current target Record 2002 October 20 after the file compression zip File.zip *-x file2.txt compression, the current directory of file2.txt files are excluded 2. Unzip unzip Aa.zip unzip File.zip x file2: In addition to Fil E2 files are extracted from other files unzip-z file.z
The following is the code for the UDP server:/* SERVER.C */#include Client code:/* client.c */#include Because the server and the client do not have the conditions to establish a connection and then communicate, the server can have concurrency capabilities.Use CTRL + C to close the server, and then run server,client to contact the server.Linux Socket Programming-UDP
Pass descriptor and SENDMSG/RECVMSG functions through UNIX domain sockets
In the front we introduced UNIX domain socket programming, and more importantly UNIX domain sockets can pass file descriptors between processes on the same host.
Let's take a look at two functions:
#include
#include
ssize_t sendmsg (int sockfd, const struct MSGHDR *msg, int flags);
ssize_t recvmsg (int sockfd, struct MSGHDR *m
In the previous article, we implemented a READN function to read fixed byte data in order to avoid the problem of sticky packets. If the length of each field in the application layer protocol is fixed, it is very convenient to read it with READN. For example, to design a client upload file protocol, specify the first 12 bytes of the file name, more than 12 bytes of file name truncation, less than 12 bytes of file name with ' "", starting from the 13th
The following is an example of the simplest client/server program to learn the socket API.
The function of the ECHOSER.C program is to read the characters from the client and then go back directly.
/************************************************************************* gt; File name:echoser.c gt; Author: Simba gt; Mail:dameng34@163.com gt; Created time:fri Mar 2013 06:15:27 PM CST ******************
The terminal processing of Linux systems is a very large system that needs to deal with many different types of devices and requirements. The content includes: modem, terminal emulation, pseudo terminal and so on.
The way the Linux system handles the terminal is to communicate with the system and run the program through a serial interface connected to the console. Because more and more manufacturers are in
set interface programming.
Static int ipfwc_init (){Ipfwc_fn = ipfwc_init;Init = 1;Return (sockfd = socket (af_inet, sock_raw, ipproto_raw ))! =-1 );}You can see that this is an original set of interfaces, But please note that the third parameter of socket, the third parameter is createdWhen the original set of interfaces is not 0, it is a constant value, repres
Landlord rookie, from the "Linux/unix system Programming Manual" to learn, learn the procedure must first run the example to play, but did not know how to do 1 hours in the book example how to run, Baidu does not come out, casually dozen a make order drink a cup of water, found out a xx.a file, the problem solved. Take
C language programming example of MongoDB in Linux
The following describes the C language programming example of MongoDB on the Linux platform.
Assume that MongoDB has been installed.
1. download and install the MongoDB C language
Publisher: chinaitlab Date: 00:00:00
Programming for sound devices in Linux is much simpler than most people think. Generally, our commonly used sound devices are internal speakers and sound cards. They all correspond to one or more device files in the/dev directory. We open them like opening common files, use the ioctl () function to set some parameters and then perform write operations on these opened spe
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.