Reputation: 1712
I want to pass message between two devices, for an example devices are PCs. Currently I am using UDPServer.c and UDPClient.c for reference. By using this reference, I can pass messages, now I want to implement both side listen and send, also I want to create an API for sending message, that API can be used by other functions. May I need to use two different port for sending message and receiving message?? what is the best way to set up UDP socket programming for message passing??
Upvotes: 0
Views: 825
Reputation: 2412
From your description, it doesn't look like you need any more than what sendto()
/recvfrom()
already do. You might as well treat them as your "API" for message passing. Once you set up/open the socket, just send/recv as needed. You don't need to worry about different ports for sending/receiving; your example is fine. FYI, you can sendto/recvfrom on the same socket.
Upvotes: 1