The server uses Java’s datagram socket and datagram packet for implementation, deployed on a server with a public IP address. One client also uses Java’s datagram socket and datagram packet, bound to port 22222, running on a Windows 11 PC, and the other is implemented in C language, bound to port 10105, running on Ubuntu.
The overall implementation process is as follows:
The two clients first send information to the server using udp, and the server saves the information of both clients. Then one of the clients will send a connection request, and the server will exchange the information between the two clients. Afterwards, the two clients send and receive udp to each other based on the received information.
Both clients use the network provided by mobile hotspot, and have tested that the NAT on Windows 11 is a full cone NAT, while the NAT on Ubuntu is a port limited cone NAT.
- When using Wireshark to capture packets on clients under Windows 11, it was found that the source and target ports of udp packets sent to the other party were incorrect.
enter image description here
2. When using Wireshark to capture packets on clients under Ubuntu, it was found that the source and target ports of the udp sent to the other party were also incorrect. Later, after using the htons function in C language to change the byte order, the source and target ports displayed in the packet capture were normal.
enter image description here
3. However, the port displayed in Windows 11 packet capture is incorrect (I know that after NAT conversion, the port number will change), but the source port displayed in packet capture is different from the port displayed on the public server.
2
Answers
This is the code for my server:
This is the code for my Windows client:
Sorry, I wrote so much that I didn’t describe the problem clearly.
The current issue is that the code of both clients cannot receive data from the other party. Wireshark can be used on Windows to capture udp packets sent by Ubuntu clients, but the source port displayed in the packet is different from the port of the Ubuntu client obtained on the server, and the target port is also different from the port of the Windows client obtained on the server. Additionally, the data part of the packet appears garbled (when using Wireshark to analyze the packet).
enter image description here
When Wireshark grabs packets sent by the local machine to the other client on Windows, the source port is not the bound 22222 port, and the target port is not the port returned by the server to the Ubuntu client.