/tmp Directory sharing allows anyone to share and read and write

/tmp *(rw,no_root_squash)

/home/test 192.168.1.*(rw) *(ro)

/etc/init.d/nfs-kernel-server start


-a The parameters are usually in NFS server Upper use , It is used to show that it has been mounted on this machine nfs Directory client machine list

-e Display the specified NFS server On export Come out of the catalog

linux Custom Web Services

Small service programs, service programs that are not often used Integrated into the server manager inetd,xinetd

extended internet services daemon Extended internet service daemon

control internet Applications for services

socket_type Network socket type Streaming packets streamTCP dgramUDP seqpacket( Reliable ordered datagram )

Configure custom network services


#description:The vsftpd server serves vsftpd sessions

service vsftpd


disable = no

port = 21

socket_type = stream

protocol = tcp

user = root

server = /usr/sbin/vsftpd

type = unlisted

wait  = no


TCP Network programming

socket addree struct How to transfer memory data between kernel and application layer

TCP Socket server and client programming framework

socket(),bind(),listen(),accept(),connect(),close() Read and send data


Interception of signals sigpipe sigintsignal

Socket address structure address struct

Different address structures have different definitions

Programming sockets Basic data structure

Socket address structure definition

socket address struct

Programming sockets Specify socket address parameters

Different protocol family Different address structures

The address structure is usually in the form of sockaddr_

General socket data structure

struct sockadrr {

sa_family_t sa_family;

char sa_data[14]; /* Protocol cluster data */


The socket data structure actually used

Socket data structure

Network programming   Socket functions take this structure as an argument

int bind(int socketfd, /* Socket file descriptor */

const struct sockaddr *my_addr; /* Socket address structure */

socketlen_t addrlen; /* The length of the socket address structure */


typedef unsigned short ;

struct socketaddr_in { Ethernet socket address structure

u8 sin_len; /* structure struct sockaddr_in length*/

u8 sin_family; /* Address cluster AF_INET address_family*/

u16 sin_port; 16 Bit port number , Network byte order

struct in_addr sin_addr; //Ip Address 32biy 4Bytes;

char sin_zero[8];


There is one ip Address

struct in_addr sin_addr ip Address

struct in_addr {

u32 s_addr;


sin_len The unsigned character type , Representation structure struct sockaddr_in

unsigned char

struct in_addr

User layer and kernel layer exchange process

Pass in data to the kernel , From the kernel Read the data Accept(),recv()

TCP Network programming architecture

TCP Network programming architecture pattern   The server   client

Server mode create service program , Waiting for client users to connect , Received a connection request from the user , Process according to the user's request

The client mode connects according to the address and port of the server

Send to the server and process the response of the server

Server side programming pattern

Tcp Server mode programming flow of end-to-end connection

Server mode programming process

Socket initialization

Socket and port binding , Set the listening connection of the server , Accept client connections   Receive and send data and process it And the socket for data transmission close()

TCP Connection server mode programming process

Socket initialization (socket()), Socket and port binding (bind()), Set the listening connection for the server (listen()), Accept client connections (accept()), Receive and send data (read(),write()),close()

During socket initialization According to the user's demand for socket

Determine the socket options Network type , Protocol type and specific protocol label

According to the needs of users Generate a socket file descriptor

Socket and port binding , The socket is bound to the address structure   Network programming   The socket represents Ip Address, port number and protocol type

The server needs to satisfy the connection requests of multiple clients , The server can only handle a limited number of client connection requests at a certain time , The server needs to set the length of the server-side queue

Server listening Limit the length of the queue in the client waiting for the server to process connection requests

The server receives client requests from socket files

Read data from socket file descriptor or send data to file descriptor

Client programming pattern

Socket initialization (socket()), Connect to server (connect()), Read and write network data (read(),write()). Process the data and close it close()

Client programming mode flow and server processing mode flow

The client initializes on the socket   No address binding    It's a direct connection to the server side

In the process of the client connecting to the server , The client uses the server address and port number set by the user etc. parameters Communicate with specific server programs

The exchange process between client and server

The client is connecting to the server , Read and write data , Close the connection    Client connection , Server receive   Conduct three way handshake establish TCP Connect    Data exchange


Create a network socket function socket()

Socket system call in network programming socket() Function to get the file descriptor

Protocol cluster domain, Protocol type type, The agreement number is protocol Socket file descriptor for , Function call succeeded , Returns a file descriptor representing the socket , Failure to return -1

#include <sys/types.h>

#include <sys/socket.h>

int socket(int domain,int type,int protocol);

domain Set the domain of network communication , Communication protocol cluster ,sys/socket.h PF_INET Address cluster , Protocol cluster

Address cluster   Protocol cluster   In the header file sys/socket.h AF_INET,PF_INET;

domain PF_UNIX,PF_LOCAL PF_INET ipv4 internet agreement

PF_INET6 agreement

PF_IPX novell

PF_NETLINK   netlink Kernel user interface program



function socket() type Set socket communication type

Streaming socket sock_STREAM,sock_dgram Data packets

sock_stream tcp Connect , Provide serialization of , reliable , Two way connected byte stream , Support out of band data transmission

sock_dgram upd Connect , Message with no connection status

sock_seqpacket Serializing packages   Provide a reliable two-way serial connection based data transmission channel   The data length is fixed Provide original network protocol access each time the read system call is called

sock_RDM Provide reliable data message

Some protocols have only specific types protocol only   sock_stream

The type is sock_stream Socket Connection to use connect Conduct

read(),write() Data transfer connect

sock_dgram raw sendto() recvfrom receive data

Receive from designated ip The sender data of the address

sock_packaet Private packets , Receiving data directly from the device driver

errno()stderr errno.h

fprintf errorno(errno);

Process file table overflow has reached the maximum number of files that the process can open at the same time

enfile The number of open files allowed by the system has been reached


struct socket{

socket_state state; /*socket state */

unsigned long flags;

const struct proto_ops *ops;

struct fasync_struct *fasync_list;

struct file *file

struct sock *sk;

wait_queue_head_t wait;


Create socket file descriptor , You need to bind the socket address and port , Receiving and sending of data

addlen struct sockaddr

int bind(int sockfd,const struct sockaddr *my_addr,socklen_t addlen);

bind The function will have a length of addlen struct sockadd Type parameter

int bind(int sockfd,const struct sockaddr *my_addr,socklen_t addrlen);

int bind(int sockfd,const struct sockaddr *my_addr,socklen_t addrlen);

socklen_t addrlen;

int sockfd,const struct sockaddr *my_addr;

const struct sockaddr *my_addr Address port ip Address information ; Address binding In the address structure ip Address port

sizeof(struct sockaddr)

struct sockaddr_un {

sa_family_t sun_family; /* Protocol cluster ,AF_UNIX*/

char sun_path[UNIX_PATH_MAX];


socket pro More articles about

  1. Path Analyzer Pro appear raw socket problem

    Use windows7,8 as well as 10 The platform runs a traceroute liketools Software , be known as Path Analyzer Pro 2.7, encounter raw socket problem , Pictured : as a result of raw socke ...

  2. socket Programming

    One .socket Address data types and related functions socket API It is an abstract network programming interface , It is suitable for various underlying network protocols , Such as IPv4.IPv6.UNIX Domain Socket. However, the address formats of various network protocols are different ...

  3. Computer virus practice summary 6 :IDA Pro Basics

    In trying to learn to analyze , The conclusion is not necessarily accurate , Just some of my own thinking and exploration . it is respectful to have you criticize and correct sth ! 1. IDA Use (1) Search for . Download and execute IDA Pro, For executable programs lab05-01.dll Loading , In figures ...

  4. Mac Pro Unpack the installation MySQL Binary distribution mysql-5.6.30-osx10.11-x86_64.tar.gz( No dmg Of )

    No, mac Of root password , The current users are sudo jurisdiction , So I want to use root All the orders executed by the identity have been added sudo. Whether there is _mysql Users and user groups , And see the users _mysql Is it a user group _mysql Members of . ...

  5. Windows Socket maximum connection

    Socket When programming , How many can a single machine set up TCP Connect , Affected by the operating system . Windows Next stand-alone TCP The number of connections is affected by multiple parameters : Maximum TCP The number of connections [HKEY_LOCAL_MACHINE \Sy ...

  6. [Arduino] be based on Xbee Pro Intelligent public transportation system design based on network technology

    from :http://www.21ic.com/app/rf/201112/99474.htm introduction Public transport has incomparable advantages over individual transport , Giving priority to the development of urban public transport system is the key to solve the problem of big . The best way to solve urban traffic problems in China . ...

  7. NodeJS+Express+Socket.io A simple example of

    keyword :NodeJS,Express,Socket.io. OS:Windows 8.1 with update pro. 1. install NodeJS:http://nodejs.org/. 2. Initialize a ...

  8. TCP SOCKET in backlog What is the purpose of the parameter ? --- The illustration

    recv_queue Packet size in , Is the package size of the kernel , instead of ip Bag size . If the bag is too big , Need modification write_queue and tx_queue Two parameters ,tx_queue It's mainly flow control . Multi process must be in sock ...

  9. Qt Study And Socket signal communication ( The simplest example in the world )

    I've been doing my homework recently Qt Of Socket part , The information about this part on the Internet is too complicated , Now let's summarize some simple applications . If you have a chance, I can tell you something Socket The code to transfer the file . Here is how to realize TCP and UDP Simple communication . ...

Random recommendation

  1. WebApp Slide up to load data ...

    $(window).bind("scroll", function () { if ($(document).scrollTop() + $(window).height() &g ...

  2. c# Version in pc Wechat code scanning payment is initiated at the end

    Waiting for a long time , Wechat official finally released .net Of demo. Main code : /** * Generate direct payments url, payment url Valid for 2 Hours , Model 2 * @param productId goods ID * @return Pattern ...

  3. Android Design Support Library: Study CoordinatorLayout

    sketch CoordinatorLayout Literally means " Coordinator layout ", It is Design Support Library A super frame layout provided in , Help us achieve Material Design ...

  4. logstash utilize drop Discard filter logs

    input { stdin { } } filter { grok { match => ["message","\s*%{TIMESTAMP_ISO8601}\s ...

  5. Windows List of common control window classes

    The following window class names are provided by the common control library: ANIMATE_CLASS Creates a ...

  6. 《Intel Compilation No 5 edition 》 Intel CPU Small end of the sequence

    One .MASM Data types in assembler Two .Intel The immediate type in assembly 3、 ... and . Define signed and unsigned integers Four . Small end of the sequence Data in memory is stored in bytes , One 4 A byte unsigned integer , Its high bit is stored in the low address , The low bits are stored in the high address . Than ...

  7. 【2016 Beijing training test competition ( Two )】 thr ( Tree form DP)

    Description Answer key ( It's an exercise that I've come across for a long time. Then I won't do it. I don't want to do it , I didn't expect to be Contest If you want to cry, you have no tears ......) The main idea is to find the number of three pairs , So that the distance between each of the three points is d. The problem lies in ...

  8. 201521123059 《Java Programming 》 The third week is the summary

    1. This week's learning summary 2. Written work 1. Code reading public class Test1 { private int i = 1;// This line cannot be modified private static int j = 2; p ...

  9. Learn the front end from scratch JAVASCRIPT — 3、JavaScript Basics string String Introduction

    1: character string JS Any data type in can be viewed as an object . therefore string It's the basic data type , Another object . 2: Declaration string Basic data type :var sStr = ' character string '; Object method :var oStr = n ...

  10. Java Traverse List5 The efficiency comparison of the two methods

    package com.test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** ...