当前位置:网站首页>Introduction to socke programming
Introduction to socke programming
2022-07-27 19:50:00 【BasilGuo】
List of articles
1. background
It took a long time ( About a week , I'm so rubbish ) After reading an English article :Bee’j Guide to Network Programming1. There's another book :《TCP/IP Sockets in C - Practical Guide for Programmers》 And a copy of PPT:《Introduction to Sockets Programming in C using TCP/IP》, No, it's just that I haven't finished reading the two later , It's older too , After all, I want to use IPv6, Instead of IPv4.【 to update , The book we are talking about now has a second edition , Joined the IPv6 The content of , Chinese translation :TCP/IP Sockets Programming (C Language implementation )】
In fact, I have studied online books in my undergraduate course , The most important thing about the network is not ISO/OSI, It is TCP/IP, After all, according to the teacher ,ISO/OSI It was a group of people who came up with it when they were drunk , They correspond to each other 7 A dwarf 2, Finally, it is later than the factual standard TCP/IP, Even according to ISO/OSI Here we are , And failed , Because it's so complicated .
2. Basics
stay TCP/IP in , Layers of abstract encapsulation , The lower layer is transparent to the upper layer , The upper layer is the data part of the lower message format , The header is some control information .
Socket Programming lies below the application layer 、 Above transport layer . Divided into Stream Socket and Datagram Socket, In fact, they correspond to the two protocols of the transport layer ,TCP and UDP. But here comes the problem , If it is DCTCP How did this kind of advanced gadget come about ? Let's discuss it later .
also C/S framework , In fact, there are two architectures :P2P as well as C/S Each has its own advantages and disadvantages , However, this article only covers C/S,B/S yes C/S A special case of ,P2P I haven't studied it yet .C/S The architecture is similar to the following figure :
by the way , The author is in *nix The platform does ,Windows Just mentioned the following :Winsock.h
3. technological process
Socket The programming process is actually not complicated .
So the whole process comes out , Is to create Socket, Then bind (bind), Actually connect() Can replace bind(), But the difference is ,bind() Binding port , and connect Don't care which port to use , Of course, for the parameters passed ,connect() Will help programmers find an unbound port to bind . The server listens for connection requests to this port , The rest is to send 、 I got the data , Note here Stream Socket( Use TCP Connect ) and Datagram Socket( Use UDP There is no connection ) The functions used for sending and receiving are different . Finally, don't forget to close Socket.
In fact, the rest is mainly to see what parameters are required for each function , Just how to use it , In the penultimate chapter of the article man pages, Or refer to another blog of mine Socket Programming based API, No post here . Theoretically, the following should be given Client/Server Of the program , But I don't think it's necessary . Follow the blog link I gave 1 There were many in the past , No more .
However, you can list the most used header files .
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
If you have the time , I'll add it when I'm more proficient .3
4. Reference resources
边栏推荐
- Optimization of embedded C language for indefinite cycles
- GestureDetector(手势识别)
- C language: 13. Pointer and memory
- 访问控制
- 【深度学习基础知识 - 41】深度学习快速入门学习资料
- 【深度学习基础知识 - 42】逻辑回归详解
- Introduction to several wireless protocols
- Come to sword finger offer 03. Repeated numbers in the array
- 【深度学习基础知识 - 40】CNN为什么比DNN在图像领域更具优势
- Flink简介以及运行架构
猜你喜欢
![[basic knowledge of deep learning - 42] detailed explanation of logistic regression](/img/74/d7d1562ada4671864961721b9a1baf.png)
[basic knowledge of deep learning - 42] detailed explanation of logistic regression

S32k series chips -- Introduction

【深度学习基础知识 - 45】机器学习中常用的距离计算方法

SharePreference(存储)

An unknown fastcgi error occurred in IIS: 0x80070005

Complete source code of E-commerce mall applet project (wechat applet)

Binary search tree

Embedded C language structure

二叉搜索树

DatePicker(日期选择器)与TimePicker(时间选择器)
随机推荐
开启和禁用hyper-v
Come to sword finger offer 03. Repeated numbers in the array
【深度学习基础知识 - 46】贝叶斯定理与条件概率公式
[basic knowledge of deep learning - 41] quick start learning materials for deep learning
Detailed explanation of the underlying data structure of redis
Uncover the mystery of Qualcomm ultrasonic fingerprint being "cracked by film"
台积电5nm即将量产:苹果A14独占7成产能,华为麒麟1020拿下3成
SharePreference(存储)
C language: 9. Return in main function
Binary search tree
注入攻击
应用程序池已被禁用
英特尔未来10年工艺路线图曝光:2029年推出1.4nm工艺!如何实现?
Ericsson admitted bribery in China and other five countries and paid a fine of $1.06 billion to the United States
Complex number proof of solvability of regular 17 sided ruler and gauge drawing
rxbinding
Fzu1669 right angled triangle
C language: 11. Pipeline
SQLServer 2008中事务日志已满问题处理
[basic knowledge of deep learning - 38] the difference between L1 regularization and L2 regularization