c++ - WSARecvFrom on unconnected UDP socket does not return -


I am writing a small program that tests a UDP network service. For the implementation of the service, a new socket for the session is allowed to be made and the customer responds to it, at which point the customer needs to talk to this address (similar to TFTP).

The minimum client looks like an error checking:

  int fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); Sockaddr_in destaddr = {...}; MSGBUF msg [] = {...}; DWORD sent; WSASendTo (fd, msg, sizeof msg / sizeof * msg, & amp; sent, 0, (sockaddr *) bit, sizeof sa, 0, 0); Four buffer [4096]; MSGBUF rcvmsg = {sizeof buffer, buffer}; DWORD received; Sockaddr_storage; Socklen_t sa_len = sizeof sa; DWORD flags = 0; WSARecvFrom (FD, and RCVMSG, 1, and Receipts, and Flags, (Socadar *) and SA, and SAL Allen, 0, 0);   

The client works fine if the server responds by the same address and port that the initial message was sent, although the answers are selected from any other port, and the client is in the WSARecvFrom Hangs up .

Obviously bind the socket to {AF_INET, INADDR_ANY, 0} to implement the local port or listen to (FD, 5); No matter, as expected.

Is there anything in WSASendTo that randomly connects a UDP socket, and if so, what should I do to avoid this?

UDP connections are not sent to datagram ports; This is the only communication.

This seems to me as if your server is allowing a temporary port to be assigned (such as passing the port in sockaddr_in 0) the specific port it does not work

Since UDP is not a concept of connection, whenever you send data, it can be sent from a separate port; The first sending port does not reserve the port which it was given, it only sends a figure and then lets it go.

Your server must be bound in a specific port.

Comments