当前位置:网站首页>Work notes: SendTo failed errno 22
Work notes: SendTo failed errno 22
2022-06-30 09:41:00 【Zip-List】
Work notes : sendto Failure errno 22
Today there is a udpclient send out udp The scenario of data to the remote server , Because they were tested on the same virtual machine before , Both the server and the client are 127.0.0.1 No problem .
The solution to online related problems is sendto Of sizeof problem , Or is it bzero The problem of .
int sock_fd ;
struct sockaddr_in send_addr, cli_addr;
bzero( &send_addr, sizeof(send_addr) );
if ((sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) == -1)
{
perror("create socket failed!\r\n");
exit(1);
}
cli_addr.sin_family = AF_INET;
cli_addr.sin_port = htons(9693);
cli_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
if (bind(sock_fd, (struct sockaddr* )&cli_addr, sizeof(cli_addr)) < 0)
{
perror("bind");
exit(EXIT_FAILURE);
}
// Initialize the pre connected server address
send_addr.sin_family = AF_INET;
send_addr.sin_port = htons(9000);
send_addr.sin_addr.s_addr = inet_addr(" Extranet ip");
int addr_length = sizeof(send_addr);
if( sendto(sock_fd, buff, cs_pkg.GetCachedSize(), 0, (struct sockaddr *)&send_addr, sizeof(send_addr)) < 0 )
After testing
c s All in the intranet All are 127.0.0.1,sendto It can send .
s After the external network or non local address ,c If it is 127.0.0.1 Unable to send normally .
Solution to c Set up a 0 / 0.0.0.0 / Or a specific network card address
127…0.0.1 and 0.0.0.0 difference
It's a complete understanding of 127.0.0.1 and 0.0.0.0 What's the difference between addresses ?
Only a maximum of... Can be maintained on a host 65535 individual TCP Is it connected ?
Subject to many restrictions ,fd, Memory ,cpu, Port number, etc . The protocol in the quintuple of the protocol , Fixed .src and dest Of ip and port Can change , More than 65535.
You may also receive NAT The limitation of ,NAT Concept :
- IP The purpose of the message IP The address is private IP Address , How the network layer handles ?
- NAT A brief introduction to the principle of LAN mapping public network
- Communication between intranet and extranet ( Port mapping principle )
Because they are all transferred from the intranet NAT Do address conversion into public network . single IP do NAT The maximum number of connections supported . agreement × source address × Source port × Destination address × Destination port = 2 * 1 * 2^16 * 2^32 * 2^16 = 3.68934881e+019 A connection ( Ideal state ) Worst case scenario , All users access the same IP The same port of the same protocol , be : agreement × source address × Source port × Destination address × Destination port = 1 * 1 * 2^16 * 1 * 1 = 65536 A connection ( The worst ).
Extended problem , Multiple processes can listen to the same port , Will it cause repeated reads , What is the shock effect
Can a port number be bound by two processes at the same time ? Corresponding nginx Multiple processes are bound to the same port number , Yes, but the condition is fork Bind a port number before , Make the child and parent processes bound to the same port number , Multiple processes reuse socketNginx
EPOLLEXCLUSIVEepoll How to solve the shock group effect
Different processes must listen to the same fd What should I do
SO_REUSEADDR SO_REUSEPROTsocket Port multiplexing SO_REUSEPORT And SO_REUSEADDR
边栏推荐
- MySQL优化
- Pass anonymous function to simplification principle
- Pit encountered by fastjason
- utils session&rpc
- Deep Learning with Pytorch - autograd
- Applet learning path 2 - event binding
- Electron, which can wrap web page programs into desktop applications
- 银河麒麟server-V10配置镜像源
- Simple redis lock
- Use V-IF with V-for
猜你喜欢
Applet learning path 2 - event binding
Notes on masking and padding in tensorflow keras
JVM notes (III): analysis of JVM object creation and memory allocation mechanism
桂林 稳健医疗收购桂林乳胶100%股权 填补乳胶产品线空白
机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)
Pit encountered by fastjason
About the smart platform solution for business hall Terminal Desktop System
抽象类和接口
JVM tuning tool introduction and constant pool explanation
Numpy (time date and time increment)
随机推荐
Use V-IF with V-for
小程序开发踩坑之旅
MCU firmware packaging Script Software
Deep Learning with Pytorch-Train A Classifier
How do I start? (continuously updating)
GPT (improving language understanding generative pre training) paper notes
Redis + MySQL implements the like function
So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!
4. use ibinder interface flexibly for short-range communication
ABAP-时间函数
thrift简单使用
Enum demo
JVM notes (III): analysis of JVM object creation and memory allocation mechanism
Using OpenCV Net for image restoration
【新书推荐】MongoDB Performance Tuning
POJ 1753 flip game (DFS 𞓜 bit operation)
Solution to the sixth training competition of 2020 provincial competition
Express get request
Clickhouse installation (quick start)
AutoUpdater. Net client custom update file