UDP is a connection-less protocol. In my server, I am using two sockets in listening mode:
sfd3000=CreateUDPSocketAndListen(3000);
sfd14000=CreateUDPSocketAndListen(4000);
I am using
socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
to create the sockets.
I am receiving the request using one socket
recvfrom(sfd3000, reqbuff,1024, 0,(struct sockaddr *)&clientinfo, (socklen_t *)&sinfolen);
Can I use the other listening socket to send the response, using the same clientinfo structure
sendto(sfd4000,respbuff,resplen, 0,(struct sockaddr *) &clientinfo, sinfolen);
Is this possible in UDP as it's a connection-less protocol?
You need not to listen for UDP protocol. You can just open and block in read if want to read some data / you can just write your data after open.
In short you can send response through another port
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.