Home > other >  Since udp is not a long link, so after the udp server receives data can return a string of data is w
Since udp is not a long link, so after the udp server receives data can return a string of data is w

Time:12-15

Since udp is not a long link, so after the udp server receives data can return a string of data is what principle, data from the server is how to find the client?

CodePudding user response:

When UDP client sends a packet to the UDP server, data bag already contains the client's IP address and port number, so the server directly to the client's IP address and port number to send response packet is ok,

CodePudding user response:

reference 1st floor kinkon007 response:
when UDP client sends a packet to the UDP server, data bag already contains the client's IP address and port number, so the server directly to the client's IP address and port number to send response packet,

Server can get Lai source IP and port of this good, at the time when the server sends data to the client the process of how to understand? This process is equivalent to the client opened an IP and port to monitor a request from the server, within this short period of time the client is also equivalent to a server?

CodePudding user response:

refer to the second floor MrWater | response:
Quote: refer to 1st floor kinkon007 response:

When UDP client sends a packet to the UDP server, data bag already contains the client's IP address and port number, so the server directly to the client's IP address and port number to send response packet,

Server can get Lai source IP and port of this good, at the time when the server sends data to the client the process of how to understand? This process is equivalent to the client opened an IP and port to monitor a request from the server, within this short period of time the client is also equivalent to a server?



When, in fact, network communication, use SOCKET, as the server, is to open a SOCKET listening, so that other clients can connect to the server, when the connection is successful, built up a SOCKET connection between the client and server, both sides can send data,
So different server and client is the server can listen other computing connection, allowing other terminal connections, and the client does not listen, do not allow the other terminal connections, but when after the success of the SOCKET connection, both sides of the equal status, can through the SOCKET send each other messages,

CodePudding user response:

Such a server, and for QQ friends message is forwarded by the server, should belong to the scope of business logic

CodePudding user response:

refer to the second floor MrWater | response:
Quote: refer to 1st floor kinkon007 response:

When UDP client sends a packet to the UDP server, data bag already contains the client's IP address and port number, so the server directly to the client's IP address and port number to send response packet,

Server can get Lai source IP and port of this good, at the time when the server sends data to the client the process of how to understand? This process is equivalent to the client opened an IP and port to monitor a request from the server, within this short period of time the client is also equivalent to a server?

When the data returned from the server to the client, the client socket has not been closed, the protocol stack will check the server data whether the destination IP address and port number to continue to open socket match, if there is a match, the upper call recvfrom will receive the data, if the client closed socket, the IP address and port number must match, the packet will not be able to reach the socket level, will be dropped, this time should not be the server, the server should be in port to bind socket layer protocol stacks,
  • Related