当前位置:网站首页>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
边栏推荐
- Distributed things
- Flutter的特别之处在哪里
- Baidu map JS browsing terminal
- Niuke rearrangement rule taking method
- Why must redis exist in distributed systems?
- Abstract classes and interfaces
- Enum demo
- Numpy (data type)
- qmlplugindump executable not found.It is required to generate the qmltypes file for VTK Qml
- Electron, which can wrap web page programs into desktop applications
猜你喜欢

机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)

oracle跨数据库复制数据表-dblink

Numpy (time date and time increment)

CentOS MySQL installation details

7. know JNI and NDK

12. problem set: process, thread and JNI architecture

Tutorial for beginners of small programs day01

Mysq database remote connection error, remote connection is not allowed

MySQL index and data storage structure foundation

Linear-gradient()
随机推荐
CentOS MySQL installation details
Deep Learning with Pytorch- A 60 Minute Blitz
ES6 learning road 5 symbol
DataTableToModelList实体类
Using OpenCV Net for image restoration
桂林 穩健醫療收購桂林乳膠100%股權 填補乳膠產品線空白
机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)
Redis docker 主从模式与哨兵sentinel
Bluetooth BT RF test (forwarding)
Reading notes of "Introduction to deep learning: pytoch"
Differences between the notify(), notifyall(), notifydatasetchanged(), notifydatasetinvalidated() methods in the adapter
ACM intensive training graph theory exercise 3 in the summer vacation of 2020 [problem solving]
Script summary
Cftpconnection:: getfile() download FTP server files and related parameter descriptions
Function simplification principle: save if you can
ReturnJson,让返回数据多一些自定义数据或类名
Alibaba billion concurrent projects in architecture
Review the old and know the new
八大排序(二)
JVM tuning tool introduction and constant pool explanation