Discover unix network programming volume 1, include the articles, news, trends, analysis and practical advice about unix network programming volume 1 on alibabacloud.com
cross-reference system is a good example of how the symbolic location information is recorded in the form of a regular expression appropriate for use by the search program.
FlexibilityYou can't expect users to be able to use your program very correctly. Therefore, you should try to consider flexibility when programming, avoid arbitrarily restricting the length of the field or the number of records. If you can, the Web program you write can run on
Overview
Today we explain a content in network programming--unix local socket.Found that a lot of people do not know or do not understand the concept of Unix local sockets, it is no wonder that the socket API is originally for the network communication between the host desi
StatementThis note does not involve SCTP, IPV6, and UNIX platform-specific knowledge. Easy to learn Winsock readers to read.
Chapter I. INTRODUCTIONDescription: Please read this blog about computer network notes Http://t.cn/zjQjulJ, here no longer repeat.
Chapter II Transport layer: TCP and UDP
User Packet Protocol UDP
The problem with UDP for network
Study Notes on Unix Network Programming Based on TCP socket programming
1. socket Functions
Int socket (int family, int type, int protocol)
Returns a socket descriptor. Error returned-1
Family indicates the protocol family. Gener
Network packet Detection
Packet Capture (sniffer): refers to the behavior of data collection on the network, which needs to be done through the NIC.
Three ways to access:
BSD Packet Filter (BPF)
SVR4 Datalink Provider Interface (DLPI)
Linux Sock_packet interface
Libpcap Library
Installation:
Apt-get Install Libpcap-dev
Common APIs
Capturing data packets
Find the default data
Unix programming toolsAuthor: Parlante, zelenski, etc.Copyright 1998-2001, stanfo UniversityIntroductionThis article describes the entire process of UNIX-based programming, including editing, compiling, linking, and debugging. There are few Common Unix
.
System IO and server model
There are mainly four I/O models under Unix/linux
Blocking I/O: (Pipe size 64K)
Simple, low efficiency, most commonly used
Read blocking
Read,readv,recv,recvfrom,recvmsg
Buffer not readable data
Write blocking
Write,writev,send,sendmag
Write buffer is less than the amount of data to write (UDP exception, no buffer concept)
Other:
Accept,connect
Non-blocking I/O:
Prevents the process from blocking on I/O
of the called program through frequently used Stdio library functions (such as fread), assuming that the type is "w", The calling program can send data to the callee using the fwrite call, and the callee can read the data on its own standard input.The type is a demo sample program for r such as the following:#include Execution Result:Output was:-linux book-desktop 2.6.31-14-generic #48-ubuntu SMP Fri Oct 14:04:26 UTC i686 gnu/linuxthe type is a demonstration sample program for w such as the fol
5 I/O models under UNIX:
1. Blocking I/O
2. Non-blocking I/O
3. I/O multiplexing (select/poll/epoll)
4. Signal-driven (Sigio)
5. Asynchronous I/O (POSIX aio_ series functions)
An input operation usually consists of two different stages:
(1) Waiting for the data to be ready.
(2) Copying data from the kernel to the process
For an input operation above a socket, t
Introduction to advanced programming in UNIX---- Programming related to the file system (I)
1. About Directories
Regardless of the operating system, when it comes to the file system, the first thing that comes to mind is directories and files. In Unix systems, everything can
client is assigned an IP address and a temporary port by the kernel.
Listen (...) indicates the passive socket interface and the specified maximum number of connections. The status is changed from closed to listen. The kernel maintains this queue for the listener interface: (1) the connection queue is not completed, the status is syn_recv, And the RTT is discarded at regular intervals; (2) the connection queue is completed and the status is establish
to exchange descriptors between parent and child processes
The new descriptor and the one before the flight in the send process point to the same file table entry in the kernel
The advantage of the UNIX domain Word throttle socket is reflected in the performance growth.
16.
If you want to wait until a fixed number of data is readable, you can call our Readn function, or specify the Msg_waitall
For non-blocking sockets, if the input operation cannot b
-stream sockets are similar to TCP sockets: They all provide a byte-stream interface with no record boundary for the process;
In Unix domain byte-stream sockets, a econnrefused error is returned immediately if the queue for the listening socket is found to be full when connect is called. In the case of TCP sockets, the TCP listener ignores these incoming SYN connection requests, and the TCP client will re-send several SYN message segments;
1. Blocking I/O model
For example, the UDP function recvfrom the kernel to the application tier, the process of invoking the application layer to the kernel is to first pass the descriptor, the receiving data buffer address, the size to the kernel, but if there is no data in the buffer corresponding to the socket at this time, then the recvfrom will be stuck (blocked) here, When the data arrives, the data is copied to the application layer, which is t
as follows:
# Include Running result:
Output was : -Linux book-desktop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686 GNU/LinuxThe example program of type W is as follows:
#include The program result is as follows:
0000000 O n c e u p o n a t i m e0000020 t h e r e w a s . . . \n0000037The above pipe function can also be used to implement client-server programs. Click this link for sample code.
Referen
Some common applications written with UDP are: DNS (domain Name System), NFS (Network File system), and SNMP (Simple Network Management Protocol).
Instead of establishing a connection with the server, the client sends a datagram to the server using the SendTo function, which must specify the address of the destination (that is, the server) as an argument. Similarly, the server does not accept connections f
First, the network program based on TCP protocol
The following figure is a general process for client/server programs based on TCP protocol:
After the server calls the socket (), bind (), listen () completes initialization, calls the accept () blocking wait, is in the listening port state, the client calls the socket () initialization, calls connect () sends the SYN segment and blocks waiting for the server to reply, The server answers a syn-ack
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.